diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2011-03-06 18:59:50 -0800 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-03-06 18:59:50 -0800 |
commit | 545a1eef6abe1d80b6336ec01696f4787808bae3 (patch) | |
tree | 7e1aa140ecbc13d8c632c9a6a50c2d6c8b414283 | |
parent | 8b432848f4fe129c9b1dcb82278313eb7890d803 (diff) | |
download | go-545a1eef6abe1d80b6336ec01696f4787808bae3.tar.gz go-545a1eef6abe1d80b6336ec01696f4787808bae3.zip |
http: add Hijacker type; remove Hijack from ResponseWriter
The Hijack functionality wasn't removed, but now you have
to test if your ResponseWriter is also a Hijacker:
func ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if hj, ok := rw.(http.Hijacker); ok {
hj.Hijack(..)
}
}
R=rsc
CC=golang-dev
https://golang.org/cl/4245064
-rw-r--r-- | src/pkg/http/httptest/recorder.go | 9 | ||||
-rw-r--r-- | src/pkg/http/server.go | 3 | ||||
-rw-r--r-- | src/pkg/rpc/server.go | 2 | ||||
-rw-r--r-- | src/pkg/websocket/server.go | 4 |
4 files changed, 6 insertions, 12 deletions
diff --git a/src/pkg/http/httptest/recorder.go b/src/pkg/http/httptest/recorder.go index 44571ddd2b..ec7bde8aae 100644 --- a/src/pkg/http/httptest/recorder.go +++ b/src/pkg/http/httptest/recorder.go @@ -6,17 +6,13 @@ package httptest import ( - "bufio" "bytes" "http" - "io" "os" ) // ResponseRecorder is an implementation of http.ResponseWriter that // records its mutations for later inspection in tests. -// -// Note that Hijack is not implemented and simply panics. type ResponseRecorder struct { Code int // the HTTP response code from WriteHeader Header http.Header // if non-nil, the headers to populate @@ -81,8 +77,3 @@ func (rw *ResponseRecorder) WriteHeader(code int) { func (rw *ResponseRecorder) Flush() { rw.Flushed = true } - -// Hijack is not implemented in ResponseRecorder and instead panics. -func (rw *ResponseRecorder) Hijack() (io.ReadWriteCloser, *bufio.ReadWriter, os.Error) { - panic("Hijack not implemented in ResponseRecorder") -} diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index 977c8c2297..a2a0e14246 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -81,7 +81,10 @@ type ResponseWriter interface { // Flush sends any buffered data to the client. Flush() +} +// A Hijacker is an HTTP request which be taken over by an HTTP handler. +type Hijacker interface { // Hijack lets the caller take over the connection. // After a call to Hijack(), the HTTP server library // will not do anything else with the connection. diff --git a/src/pkg/rpc/server.go b/src/pkg/rpc/server.go index 9dcda41480..f185cd16e5 100644 --- a/src/pkg/rpc/server.go +++ b/src/pkg/rpc/server.go @@ -527,7 +527,7 @@ func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "405 must CONNECT\n") return } - conn, _, err := w.Hijack() + conn, _, err := w.(http.Hijacker).Hijack() if err != nil { log.Print("rpc hijacking ", w.RemoteAddr(), ": ", err.String()) return diff --git a/src/pkg/websocket/server.go b/src/pkg/websocket/server.go index 25f057ba5b..37149f044d 100644 --- a/src/pkg/websocket/server.go +++ b/src/pkg/websocket/server.go @@ -58,7 +58,7 @@ func getKeyNumber(s string) (r uint32) { // ServeHTTP implements the http.Handler interface for a Web Socket func (f Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - rwc, buf, err := w.Hijack() + rwc, buf, err := w.(http.Hijacker).Hijack() if err != nil { panic("Hijack failed: " + err.String()) return @@ -184,7 +184,7 @@ func (f Draft75Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - rwc, buf, err := w.Hijack() + rwc, buf, err := w.(http.Hijacker).Hijack() if err != nil { panic("Hijack failed: " + err.String()) return |