<commit_before>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// HTTP server.  See RFC 2616.

// TODO(rsc):
//	logging
//	cgi support
//	post support

package http

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"net"
	"os"
	"path"
	"strconv"
	"strings"
)

// Errors introduced by the HTTP server.
var (
	ErrWriteAfterFlush = os.NewError("Conn.Write called after Flush")
	ErrHijacked        = os.NewError("Conn has been hijacked")
)

// Objects implementing the Handler interface can be
// registered to serve a particular path or subtree
// in the HTTP server.
type Handler interface {
	ServeHTTP(*Conn, *Request)
}

// A Conn represents the server side of a single active HTTP connection.
type Conn struct {
	RemoteAddr string   // network address of remote side
	Req        *Request // current HTTP request

	rwc      io.ReadWriteCloser // i/o connection
	buf      *bufio.ReadWriter  // buffered rwc
	handler  Handler            // request handler
	hijacked bool               // connection has been hijacked by handler

	// state for the current reply
	closeAfterReply bool              // close connection after this reply
	chunking        bool              // using chunked transfer encoding for reply body
	wroteHeader     bool              // reply header has been written
	header          map[string]string // reply header parameters
	written         int64             // number of bytes written in body
	status          int               // status code passed to WriteHeader
}

// Create new connection from rwc.
func newConn(rwc net.Conn, handler Handler) (c *Conn, err os.Error) {
	c = new(Conn)
	if a := rwc.RemoteAddr(); a != nil {
		c.RemoteAddr = a.String()
	}
	c.handler = handler
	c.rwc = rwc<commit_msg>http: clarify ServeHTTP return<commit_after>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// HTTP server.  See RFC 2616.

// TODO(rsc):
//	logging
//	cgi support
//	post support

package http

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"net"
	"os"
	"path"
	"strconv"
	"strings"
)

// Errors introduced by the HTTP server.
var (
	ErrWriteAfterFlush = os.NewError("Conn.Write called after Flush")
	ErrHijacked        = os.NewError("Conn has been hijacked")
)

// Objects implementing the Handler interface can be
// registered to serve a particular path or subtree
// in the HTTP server.
//
// ServeHTTP should write reply headers and data to the Conn
// and then return.  Returning signals that the request is finished
// and that the HTTP server can move on to the next request on
// the connection.
type Handler interface {
	ServeHTTP(*Conn, *Request)
}

// A Conn represents the server side of a single active HTTP connection.
type Conn struct {
	RemoteAddr string   // network address of remote side
	Req        *Request // current HTTP request

	rwc      io.ReadWriteCloser // i/o connection
	buf      *bufio.ReadWriter  // buffered rwc
	handler  Handler            // request handler
	hijacked bool               // connection has been hijacked by handler

	// state for the current reply
	closeAfterReply bool              // close connection after this reply
	chunking        bool              // using chunked transfer encoding for reply body
	wroteHeader     bool              // reply header has been written
	header          map[string]string // reply header parameters
	written         int64             // number of bytes written in body
	status          int               // status code passed to WriteHeader
}

// Create new connection from rwc.
func newConn(rwc net.Conn, handler Handler) (c *Conn, err os.Error) {
	c = new(Conn)
	if a := rwc.RemoteAddr(); a != nil {
		c.RemoteAddr = a.String()
	}
	c.handler = handler
	c.rwc = rwc
{'fraction_non_alphanumeric': 0.0821106821106821, 'fraction_numerical': 0.005148005148005148, 'mean_word_length': 2.460373998219056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2189490', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1087, 'n_words': 465}