From 080aa8e9647e5211650f34f3a93fb493afbe396d Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 3 Mar 2026 08:12:25 -0800 Subject: net/http: use net/http/internal/http2 rather than h2_bundle.go Rework net/http/internal/http2 to use internally-defined types rather than net/http types (to avoid an import cycle). Remove h2_bundle.go, and replace it with calls into net/http/internal/http2 instead. For #67810 Change-Id: I56a1b28dbd0e302ab15a30f819dd46256a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/751304 Reviewed-by: Nicholas Husin LUCI-TryBot-Result: Go LUCI Auto-Submit: Damien Neil Reviewed-by: Nicholas Husin --- src/net/http/clientserver_test.go | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/net/http/clientserver_test.go') diff --git a/src/net/http/clientserver_test.go b/src/net/http/clientserver_test.go index 2bca1d3253..c25db82fe4 100644 --- a/src/net/http/clientserver_test.go +++ b/src/net/http/clientserver_test.go @@ -178,7 +178,7 @@ var optFakeNet = new(struct{}) // The optFakeNet option configures the server and client to use a fake network implementation, // suitable for use in testing/synctest tests. func newClientServerTest(t testing.TB, mode testMode, h Handler, opts ...any) *clientServerTest { - if mode == http2Mode { + if mode == http2Mode || mode == http2UnencryptedMode { CondSkipHTTP2(t) } cst := &clientServerTest{ @@ -205,12 +205,6 @@ func newClientServerTest(t testing.TB, mode testMode, h Handler, opts ...any) *c cst.ts = httptest.NewUnstartedServer(h) } - if mode == http2UnencryptedMode { - p := &Protocols{} - p.SetUnencryptedHTTP2(true) - cst.ts.Config.Protocols = p - } - for _, opt := range opts { switch opt := opt.(type) { case func(*Transport): @@ -228,16 +222,23 @@ func newClientServerTest(t testing.TB, mode testMode, h Handler, opts ...any) *c cst.ts.Config.ErrorLog = log.New(testLogWriter{t}, "", 0) } + p := &Protocols{} + if cst.ts.Config.Protocols == nil { + cst.ts.Config.Protocols = p + } switch mode { case http1Mode: + p.SetHTTP1(true) cst.ts.Start() case https1Mode: + p.SetHTTP1(true) cst.ts.StartTLS() case http2UnencryptedMode: - ExportHttp2ConfigureServer(cst.ts.Config, nil) + p.SetUnencryptedHTTP2(true) cst.ts.Start() case http2Mode: - ExportHttp2ConfigureServer(cst.ts.Config, nil) + p.SetHTTP2(true) + cst.ts.EnableHTTP2 = true cst.ts.TLS = cst.ts.Config.TLSConfig cst.ts.StartTLS() default: @@ -245,18 +246,10 @@ func newClientServerTest(t testing.TB, mode testMode, h Handler, opts ...any) *c } cst.c = cst.ts.Client() cst.tr = cst.c.Transport.(*Transport) - if mode == http2Mode || mode == http2UnencryptedMode { - if err := ExportHttp2ConfigureTransport(cst.tr); err != nil { - t.Fatal(err) - } - } for _, f := range transportFuncs { f(cst.tr) } - - if mode == http2UnencryptedMode { - p := &Protocols{} - p.SetUnencryptedHTTP2(true) + if cst.tr.Protocols == nil { cst.tr.Protocols = p } @@ -1163,10 +1156,9 @@ func testTransportDiscardsUnneededConns(t *testing.T, mode testMode) { c := noteCloseConn{rc, func() { atomic.AddInt32(&numClose, 1) }} return tls.Client(c, tlsConfig), nil }, + Protocols: &Protocols{}, } - if err := ExportHttp2ConfigureTransport(tr); err != nil { - t.Fatal(err) - } + tr.Protocols.SetHTTP2(true) defer tr.CloseIdleConnections() c := &Client{Transport: tr} @@ -1725,6 +1717,16 @@ func TestH12_WebSocketUpgrade(t *testing.T) { } res.Proto = "HTTP/IGNORE" // skip later checks that Proto must be 1.1 vs 2.0 }, + Opts: []any{ + func(s *Server) { + // Configure servers to support HTTP/1 and HTTP/2, + // so we can verify that we use HTTP/1 + // even when HTTP/2 is an option. + s.Protocols = &Protocols{} + s.Protocols.SetHTTP1(true) + s.Protocols.SetHTTP2(true) + }, + }, }.run(t) } -- cgit v1.3