-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: document explicitly that http2 doesn't support Hijacker #15312
Comments
The docs on https://golang.org/pkg/net/http/#Hijacker do already say "The Hijacker interface is implemented by ResponseWriters that allow an HTTP handler to take over the connection", which is trying to say that not all ResponseWriters support that. If they did, it would just be part of the ResponseWriter interface. To do this without hijack, just write to your ResponseWriter and use https://golang.org/pkg/net/http/#Flusher instead. Both http1 and http2 support Flusher (but you should still test for it and conditionally use it). There's no need to use a buffered writer. The http1 and http2 response writers are already buffered. (and any unbuffered one wouldn't need a flush) |
I'll repurpose this bug to be about documentation. |
Thanks, your solution works fine! About the docs I understand. I'm not saying that it is incorrect, I'm saying that it could be more useful. I understand that use cases for Hijacker are limited but I'm glad you decided to document it, thanks. |
CL https://golang.org/cl/22122 mentions this issue. |
When I upgraded to go1.6 (Linux amd64) our applications, which rely heavily on Server-sent events, stopped working because *http2responseWriter does not implement http.Hijacker (#14797) (tried Firefox only).
I'm not using any SSE package, see code below (slightly edited), and it worked fine for 4 years until go1.6.
As I said in the referenced issue, I think there is a problem with the documentation because I relied on a feature that stopped working without warning.
I propose to document that *http2responseWriter is not an Hijacker and any other possible case, so that people can evaluate if and when to rely on the hijacking feature and how to set up the server so that it may fail only for external causes.
It may seems that there are no sensible uses for hijacking besides websockets, but you never know, in fact I was using it for SSE.
EDIT: I realize I can't expect my code to work across http versions if I hardcode the version myself, but even if the version was correct it doesn't reach past the type assertion. How should I go about rewriting this without hijacking?
The text was updated successfully, but these errors were encountered: