Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: net/http: add Promise() method to Pusher interface #24984
What version of Go are you using (
changed the title
net/http: Add Promise() method to Pusher interface (http/2 PUSH_PROMISE)
Apr 21, 2018
This bug immediately proposes a solution. I'd rather see the problem statement in one self-contained place before we discuss solutions. It's hard reading bugs that are just a bunch of links to other threads.
If the problem is lower priority pushed data being written to the client before the higher priority response, you could just not write that low priority data in your ServeHTTP ResponseWriter.Write until your other request is done. That might require too much coordination between far removed parts of your code. Is it too hard for your http.Handler to detect requests which are pushed requests? I seem to recall a thread about how to do that. The other option is adding some field (
@bradfitz That sounds like an interesting workaround. I will try to implement this synchronization.
Please feel free to correct me here, but that sounds more like a temporary workaround rather than a correct implementation of HTTP/2.
I am only basing this on a minimal understanding of the specification, please educate me if the spec is different than what I described as a solution (sending PUSH_PROMISE frames, immediately returning).
You're making the incorrect assumption that we're always sending the PUSH_PROMISE and its data together at once on the wire.
What we actually do is schedule a PUSH_PROMISE frame to be written at some point, and then start a new goroutine for ServeHTTP on your pushed request, running concurrently with the ServeHTTP that did the push. Now both are running. Whichever writes its data first to its ResponseWriter first gets its data send on the HTTP/2 connection first. If you coordinate between your two, you can control it, but usually it won't matter and writing anything is better than writing nothing, so our default behavior works out pretty well with no work.
If you have specific ordering requirements, you need to synchronize with your handlers a bit more on who Writes when.
@bradfitz Thank you for the detailed explanation! That was very helpful.
I will try to implement the suggested synchronization to my web server and if there are no problems I believe this issue can be closed.
Edit: One last question though, is it guaranteed that the PUSH_PROMISE frame arrives before the HTML response when