I\'m using Go and trying to implement WebSocket in my project. while implementing this. I get "WebSocket: response does not implement HTTP.Hijacker" error. I\'m ne
The application is using "middleware" that wraps the net/http server's ResponseWriter implementation. The middleware wrapper does not implement the Hijacker interface.
There are two fixes for the problem:
Remove the offending middleware.
Implement the Hijacker interface on the middleware wrapper by delegating through to the underlying response. The method implementation will look something like this:
func (w *wrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
h, ok := w.underlyingResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, errors.New("hijack not supported")
}
return h.Hijack()
}
If you don't know what the response writer wrapper is, add a statement to print the type from the handler:
func HandleConnections(w http.ResponseWriter, r *http.Request) {
fmt.Printf("w's type is %T\n", w)
...