kataras / muxie

Muxie is a modern, fast and light HTTP multiplexer for Go. Fully compatible with the http.Handler interface. Written for everyone.
MIT License
282 stars 24 forks source link

websocket: response does not implement http.Hijacker #12

Open TommasoAmici opened 3 years ago

TommasoAmici commented 3 years ago

Hi, I'm trying to use this library with WebSockets using https://github.com/gorilla/websocket, but I get this error when the server attempts to upgrade the connection.

websocket: response does not implement http.Hijacker

If I revert to the standard library with

mux := http.NewServeMux()

everything works fine

kataras commented 2 years ago

Hello @TommasoAmici sorry for the delay,

You need to cast ResponseWriter to *muxie.Writer and then get its standard writer, example code:

    mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
        serveWs(hub, w.(*muxie.Writer).ResponseWriter, r)
    })

Example: https://github.com/kataras/muxie/tree/master/_examples/14_websocket