Skip to content

net/http: add server push for HTTP/2 - #716

Merged
tamnd merged 1 commit into
mainfrom
http2-push
Oct 27, 2026
Merged

tamnd merged 1 commit into
mainfrom
http2-push

Conversation

@tamnd

@tamnd tamnd commented Oct 27, 2026

Copy link
Copy Markdown
Owner

What this adds

HTTP/2 server push, from Go 1.27.3's net/http/internal/http2 server and server_push_test.go.

Go burrow
http.Pusher, Push(target, opts) HttpPusherVT, the new push slot of HttpResponseWriterVT
http.PushOptions HttpPushOptions (method, header)
http.Flusher, http.Hijacker, http.CloseNotifier HttpFlusherVT, HttpHijackerVT, HttpCloseNotifierVT, typedefs of the vtable they live in
(*responseWriter).Push h2s_rw_push
(*serverConn).startPush h2s_start_push
(*serverConn).allocatePromisedID h2s_allocate_promised_id

h2s_rw_push makes 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_push in the tests gives an error for a writer with no push slot, where Go's type assertion would panic.

Breaking change

HttpResponseWriterVT has a new last slot, push. A vtable written with positional initializers needs one more NULL at 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 but TestServer_Push_StateTransitions are at the end of tests/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_pipe where Go's fake connection buffers what the server writes:

  • TestServer_Push_Success reads the frames before it waits for the handlers. The pushed handlers can only finish once their frames are read.
  • The handler sets Content-Length to a literal ("23", len(mainBody)), as the other tests in the file do. http_header_set keeps 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 --- PASS lines.

Test binary Result
http2_server_test 139 pass, TestServer_Push_Success failed with timeout waiting for handler 1 to finish and the same for handler 2
http_serve_test PASS, 19
cgi_test PASS, 32
fcgi_test PASS, 8
http_fs_test PASS, 39
http_mux_test PASS, 28
http_request_test PASS, 22
httptest_test PASS, 16

Under gcc's ASan and UBSan, -test.run Push stopped in TestServer_Push_Success with a heap-use-after-free. str_clone in h2s_write_chunk read the Content-Length the handler had made with strconv_itoa in its own arena, which h2t_push_handler had 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 --check says 997 example blocks match, check-headers, check-errout, the cheatsheet check and clang-format are clean, and burrow-coverage has net/http at 493/505.

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.
@tamnd tamnd added port Porting a standard library package, or part of one area: pure Packages with no OS and no concurrency: strings through regexp labels Oct 27, 2026
Comment thread src/net/http2_server.c
* 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) {
@tamnd
tamnd merged commit 1aa7ea0 into main Oct 27, 2026
34 of 46 checks passed
@tamnd
tamnd deleted the http2-push branch October 27, 2026 14:07
@tamnd tamnd mentioned this pull request Oct 27, 2026
23 of 27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: pure Packages with no OS and no concurrency: strings through regexp port Porting a standard library package, or part of one

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants