Commit 2168e6aa authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http: change Hijacker to return a net.Conn

net.Conn is itself a io.ReadWriteCloser, so
most code should be unaffected.

R=rsc, gburd
CC=golang-dev
https://golang.org/cl/4261052
parent 792ff386
...@@ -83,24 +83,25 @@ type ResponseWriter interface { ...@@ -83,24 +83,25 @@ type ResponseWriter interface {
Flush() Flush()
} }
// A Hijacker is an HTTP request which be taken over by an HTTP handler. // The Hijacker interface is implemented by ResponseWriters that allow
// an HTTP handler to take over the connection.
type Hijacker interface { type Hijacker interface {
// Hijack lets the caller take over the connection. // Hijack lets the caller take over the connection.
// After a call to Hijack(), the HTTP server library // After a call to Hijack(), the HTTP server library
// will not do anything else with the connection. // will not do anything else with the connection.
// It becomes the caller's responsibility to manage // It becomes the caller's responsibility to manage
// and close the connection. // and close the connection.
Hijack() (io.ReadWriteCloser, *bufio.ReadWriter, os.Error) Hijack() (net.Conn, *bufio.ReadWriter, os.Error)
} }
// A conn represents the server side of an HTTP connection. // A conn represents the server side of an HTTP connection.
type conn struct { type conn struct {
remoteAddr string // network address of remote side remoteAddr string // network address of remote side
handler Handler // request handler handler Handler // request handler
rwc io.ReadWriteCloser // i/o connection rwc net.Conn // i/o connection
buf *bufio.ReadWriter // buffered rwc buf *bufio.ReadWriter // buffered rwc
hijacked bool // connection has been hijacked by handler hijacked bool // connection has been hijacked by handler
usingTLS bool // a flag indicating connection over TLS usingTLS bool // a flag indicating connection over TLS
} }
// A response represents the server side of an HTTP response. // A response represents the server side of an HTTP response.
...@@ -475,8 +476,9 @@ func (c *conn) serve() { ...@@ -475,8 +476,9 @@ func (c *conn) serve() {
c.close() c.close()
} }
// Hijack impements the ResponseWriter.Hijack method. // Hijack implements the Hijacker.Hijack method. Our response is both a ResponseWriter
func (w *response) Hijack() (rwc io.ReadWriteCloser, buf *bufio.ReadWriter, err os.Error) { // and a Hijacker.
func (w *response) Hijack() (rwc net.Conn, buf *bufio.ReadWriter, err os.Error) {
if w.conn.hijacked { if w.conn.hijacked {
return nil, nil, ErrHijacked return nil, nil, ErrHijacked
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment