Repository navigation
net/http: add server push for HTTP/2 - #716
Merged
Merged
Conversation
Pusher and PushOptions are here, with a push slot at the end of HttpResponseWriterVT. The HTTP/2 response writer fills it with a port of responseWriter.Push, and the serve loop sends the PUSH_PROMISE and starts the pushed handler the way startPush does. The timeout writer passes Push through, as Go's does. The tests are a port of server_push_test.go, over TLS like Go's.
This was referenced Oct 27, 2026
| * req. NULL and an error, or req. */ | ||
| static HttpRequest *h2s_new_writer_and_request_no_body(h2s_Conn *sc, h2s_Stream *st, | ||
| HttpRequest *req, | ||
| h2s_ReqParam rp, Error *err) { |
23 of 27 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
HTTP/2 server push, from Go 1.27.3's
net/http/internal/http2server andserver_push_test.go.http.Pusher,Push(target, opts)HttpPusherVT, the newpushslot ofHttpResponseWriterVThttp.PushOptionsHttpPushOptions(method,header)http.Flusher,http.Hijacker,http.CloseNotifierHttpFlusherVT,HttpHijackerVT,HttpCloseNotifierVT, typedefs of the vtable they live in(*responseWriter).Pushh2s_rw_push(*serverConn).startPushh2s_start_push(*serverConn).allocatePromisedIDh2s_allocate_promised_idh2s_rw_pushmakes Go's checks, with Go's error messages: no push from a pushed stream, an absolute URL or a path, the scheme the connection uses, a host, no pseudo or forbidden headers, and GET or HEAD only. It then hands the push to the serve loop and waits for the PUSH_PROMISE to be written, the stream to close, or the connection to end. The promised stream starts half closed (remote), with a handler of its own.Two cases are "Not in Go". A failure to allocate the promised stream's request or start its handler closes the stream again.
h2t_pushin the tests gives an error for a writer with no push slot, where Go's type assertion would panic.Breaking change
HttpResponseWriterVThas a new last slot,push. A vtable written with positional initializers needs one moreNULLat the end. The ten in the repo have it (the docs example,cgi_child.c,fcgi_child.c,http_filetransport.c,http_serve.c,httptest.c, and four tests).Tests
All 12 of
server_push_test.go's tests butTestServer_Push_StateTransitionsare at the end oftests/http2_server_test.c. That one looks at the server's stream states. Like Go's, they talk TLS.Two of the test changes are "Not in Go", because the tester runs over a
net_pipewhere Go's fake connection buffers what the server writes:TestServer_Push_Successreads the frames before it waits for the handlers. The pushed handlers can only finish once their frames are read."23",len(mainBody)), as the other tests in the file do.http_header_setkeeps the value, which is sent after the handler returns.Results
These are from server1 with gcc, on the first version of the branch. It had both test problems above, and the counts are of top level
--- PASSlines.http2_server_testTestServer_Push_Successfailed withtimeout waiting for handler 1 to finishand the same for handler 2http_serve_testcgi_testfcgi_testhttp_fs_testhttp_mux_testhttp_request_testhttptest_testUnder gcc's ASan and UBSan,
-test.run Pushstopped inTestServer_Push_Successwith a heap-use-after-free.str_cloneinh2s_write_chunkread the Content-Length the handler had made withstrconv_itoain its own arena, whichh2t_push_handlerhad already freed. That's the second fix above. None of the runs had a skip.The servers don't have 5G free at the moment, so the fixed branch hasn't been run on them. CI's jobs, the sanitizer ones included, are its first full run. Locally,
burrow-gen doc --checksays 997 example blocks match, check-headers, check-errout, the cheatsheet check and clang-format are clean, andburrow-coveragehasnet/httpat 493/505.