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
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
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")
-}
// 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.
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
// 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
return
}
- rwc, buf, err := w.Hijack()
+ rwc, buf, err := w.(http.Hijacker).Hijack()
if err != nil {
panic("Hijack failed: " + err.String())
return