Skip to content

Commit 49810da

Browse files
committed
http2: enable net/http wrapping when go >= 1.27
When building with Go 1.27 or newer, use an HTTP/2 client and server which are implemented in terms of net/http. The original source of truth for the Go HTTP/2 implementation was the x/net/http2 package. A copy of this package was included in the standard library. In Go 1.27, the source of truth of the HTTP/2 implementation has moved entirely into the standard library. There are no supported features of the HTTP/2 implementation which require importing x/net/http2, and most users should just use net/http directly. We still support existing code which imports x/net/http2. To avoid maintaining two divergent HTTP/2 implementations, x/net/http2 (when used with a recent enough version of Go) now just wraps net/http. For now, users may revert to the the pre-Go 1.27 implementation by setting the build tag "http2legacy": go build -tags=http2legacy ... For golang/go#78508 Change-Id: I6efeddc4f3bcba9388c19cbcd1e9b8a56a6a6964 Reviewed-on: https://go-review.googlesource.com/c/net/+/774440 LUCI-TryBot-Result: [email protected] <[email protected]> Reviewed-by: Nicholas Husin <[email protected]> Reviewed-by: Nicholas Husin <[email protected]>
1 parent 5e11a5a commit 49810da

31 files changed

Lines changed: 36 additions & 39 deletions

‎http2/README.md‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,5 @@ This is called "the wrapping implementation", since it wraps net/http.
1515

1616
The original implementation is used when the Go version is less than 1.27.
1717

18-
When the Go version is 1.27 or higher, the original implementation is used
19-
by default and the wrapping "http2wrap" build tag
20-
21-
When the Go version is less than Go 1.27 and the "http2wrap" build tag is set,
22-
the wrapping implementation is used. Otherwise, the original implementaiton is used.
18+
The wrapping implementation is used when the Go version is at least 1.27.
19+
The build tag "http2legacy" may be set to use the original implementation.

‎http2/client_conn_pool.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !(go1.27 && http2wrap)
5+
//go:build !(go1.27 && !http2legacy)
66

77
// Transport code's client connection pooling.
88

‎http2/clientconn_go126_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build go1.26 && !(go1.27 && http2wrap)
5+
//go:build go1.26 && !(go1.27 && !http2legacy)
66

77
// Go 1.26 and later: http.ClientConn available.
88

‎http2/clientconn_nowrap_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !(go1.27 && http2wrap)
5+
//go:build !(go1.27 && !http2legacy)
66

77
// Using the HTTP/2 implementation in this package:
88
// Internal package hooks available.

‎http2/clientconn_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func testTestClientConn(t testing.TB) {
5252
req, _ := http.NewRequest("PUT", "https://dummy.tld/", body)
5353
rt := tc.roundTrip(req)
5454

55-
// Note: rt.streamID can give the stream ID, but not when using http2wrap.
55+
// Note: rt.streamID can give the stream ID, but only with http2legacy.
5656
streamID := uint32(1)
5757

5858
// tc has a number of methods to check for expected frames sent.

‎http2/clientconn_wrap_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build go1.27 && http2wrap
5+
//go:build go1.27 && !http2legacy
66

77
// Wrapping the HTTP/2 implementation in net/http/internal/http2:
88
// Internal package hooks not available.

‎http2/config.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !(go1.27 && http2wrap)
5+
//go:build !(go1.27 && !http2legacy)
66

77
package http2
88

‎http2/config_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !(go1.27 && http2wrap)
5+
//go:build !(go1.27 && !http2legacy)
66

77
package http2_test
88

‎http2/export_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !(go1.27 && http2wrap)
5+
//go:build !(go1.27 && !http2legacy)
66

77
package http2
88

‎http2/export_wrap_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build go1.27 && http2wrap
5+
//go:build go1.27 && !http2legacy
66

77
package http2
88

@@ -14,5 +14,5 @@ func (t *Transport) TestTransport() *http.Transport {
1414
}
1515

1616
func (s *Server) TestSetNewConnFunc(f func(*ServerConn)) {
17-
panic("ServerConns are not available with http2wrap")
17+
panic("ServerConns are only available with http2legacy")
1818
}

0 commit comments

Comments
 (0)