diff options
| author | Nicholas S. Husin <nsh@golang.org> | 2026-01-26 18:15:57 -0500 |
|---|---|---|
| committer | Nicholas Husin <nsh@golang.org> | 2026-03-04 06:38:17 -0800 |
| commit | 0b9bcbc58c4cf127d5a42989d08cc0236faa71cc (patch) | |
| tree | a57ec2091bd435af3af8c0e983ad43b7f088db72 /src/net/http/http.go | |
| parent | fdf3bee34261f383e394a06b1e4cf87fff684c1b (diff) | |
| download | go-0b9bcbc58c4cf127d5a42989d08cc0236faa71cc.tar.xz | |
net/http: add basic unexported pluggable HTTP/3 support
Following #77440, this CL adds a basic support for plugging in an HTTP/3
implementation to net/http. As the proposal is not accepted yet, this CL
does not add any exported symbols.
Access to plug HTTP/3 support is locked behind
net/http.protocolSetHTTP3, which can only be used via linkname by
golang.org/x/net/internal/http3_test.protocolSetHTTP3. This will allow
us to run our HTTP/3 implementation in x/net againts various tests in
net/http to support development, without expanding the API surface for
any users.
Support for closeIdleConnectionser will be added separately in the
future.
For #77440
Change-Id: I6e3a0c2e9b329cef43e4682463ed5e2093d04256
Reviewed-on: https://go-review.googlesource.com/c/go/+/740120
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/net/http/http.go')
| -rw-r--r-- | src/net/http/http.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/net/http/http.go b/src/net/http/http.go index 100d4fe4a1..dc4e3ba14d 100644 --- a/src/net/http/http.go +++ b/src/net/http/http.go @@ -12,6 +12,7 @@ import ( "strings" "time" "unicode/utf8" + _ "unsafe" "golang.org/x/net/http/httpguts" ) @@ -35,6 +36,7 @@ const ( protoHTTP1 = 1 << iota protoHTTP2 protoUnencryptedHTTP2 + protoHTTP3 ) // HTTP1 reports whether p includes HTTP/1. @@ -55,6 +57,15 @@ func (p Protocols) UnencryptedHTTP2() bool { return p.bits&protoUnencryptedHTTP2 // SetUnencryptedHTTP2 adds or removes unencrypted HTTP/2 from p. func (p *Protocols) SetUnencryptedHTTP2(ok bool) { p.setBit(protoUnencryptedHTTP2, ok) } +// http3 reports whether p includes HTTP/3. +func (p Protocols) http3() bool { return p.bits&protoHTTP3 != 0 } + +// setHTTP3 adds or removes HTTP/3 from p. +func (p *Protocols) setHTTP3(ok bool) { p.setBit(protoHTTP3, ok) } + +//go:linkname protocolSetHTTP3 golang.org/x/net/internal/http3_test.protocolSetHTTP3 +func protocolSetHTTP3(p *Protocols) { p.setHTTP3(true) } + func (p *Protocols) setBit(bit uint8, ok bool) { if ok { p.bits |= bit @@ -63,6 +74,11 @@ func (p *Protocols) setBit(bit uint8, ok bool) { } } +// empty returns true if p has no protocol set at all. +func (p Protocols) empty() bool { + return p.bits == 0 +} + func (p Protocols) String() string { var s []string if p.HTTP1() { |
