alexedwards / scs

HTTP Session Management for Go
MIT License
2.09k stars 166 forks source link

Can I use this if I'm using websockets? #82

Closed jherman closed 4 years ago

jherman commented 4 years ago

Hi,

When I attempt to use websockets, in this case I'm using nhooyr.io/websocket, I get http: response.WriteHeader on hijacked connection from github.com/alexedwards/scs.(*SessionManager).LoadAndSave.func1 (session.go:159) exceptions. Is there something I'm not taking into consideration when using sessions and websockets?

1gm commented 4 years ago

Websockets & SCS are incompatible on the same http.ResponseWriter due to both libraries attempting to handle the lifetime of the connection via http hijacking.

alexedwards commented 4 years ago

Like @1gm says, the difficulty is that the connection is hijacked for the websocket, so the SCS LoadAndSave middleware can't write back to the http.ResponseWriter without an error. SCS doesn't hijack the connection.