aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/http.go
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2024-11-04 11:21:04 -0800
committerDamien Neil <dneil@google.com>2024-11-21 23:48:38 +0000
commit66abc557077c026cf21b228fe0f53afe652a4d1c (patch)
tree6030d19f58708a69c485faf3d80f738fe6494023 /src/net/http/http.go
parentc0bccdd2fd2a26c34b30ec93e64fa1ebe704dc10 (diff)
downloadgo-66abc557077c026cf21b228fe0f53afe652a4d1c.tar.xz
net/http: add support for unencrypted HTTP/2
Add an UnencryptedHTTP2 protocol value. Both Server and Transport implement "HTTP/2 with prior knowledge" as described in RFC 9113, section 3.3. Neither supports the deprecated HTTP/2 upgrade mechanism (RFC 7540, section 3.2 "h2c"). For Server, UnencryptedHTTP2 controls whether the server will accept HTTP/2 connections on unencrypted ports. When enabled, the server checks new connections for the HTTP/2 preface and routes them appropriately. For Transport, enabling UnencryptedHTTP2 and disabling HTTP1 causes http:// requests to be made over unencrypted HTTP/2 connections. For #67816 Change-Id: I2763c4cdec1c2bc6bb8157edb93b94377de8a59b Reviewed-on: https://go-review.googlesource.com/c/go/+/622976 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/http.go')
-rw-r--r--src/net/http/http.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/net/http/http.go b/src/net/http/http.go
index 55f518607d..4da77889b1 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -24,6 +24,8 @@ import (
// HTTP1 is supported on both unsecured TCP and secured TLS connections.
//
// - HTTP2 is the HTTP/2 protcol over a TLS connection.
+//
+// - UnencryptedHTTP2 is the HTTP/2 protocol over an unsecured TCP connection.
type Protocols struct {
bits uint8
}
@@ -31,6 +33,7 @@ type Protocols struct {
const (
protoHTTP1 = 1 << iota
protoHTTP2
+ protoUnencryptedHTTP2
)
// HTTP1 reports whether p includes HTTP/1.
@@ -45,6 +48,12 @@ func (p Protocols) HTTP2() bool { return p.bits&protoHTTP2 != 0 }
// SetHTTP2 adds or removes HTTP/2 from p.
func (p *Protocols) SetHTTP2(ok bool) { p.setBit(protoHTTP2, ok) }
+// UnencryptedHTTP2 reports whether p includes unencrypted HTTP/2.
+func (p Protocols) UnencryptedHTTP2() bool { return p.bits&protoUnencryptedHTTP2 != 0 }
+
+// SetUnencryptedHTTP2 adds or removes unencrypted HTTP/2 from p.
+func (p *Protocols) SetUnencryptedHTTP2(ok bool) { p.setBit(protoUnencryptedHTTP2, ok) }
+
func (p *Protocols) setBit(bit uint8, ok bool) {
if ok {
p.bits |= bit
@@ -61,6 +70,9 @@ func (p Protocols) String() string {
if p.HTTP2() {
s = append(s, "HTTP2")
}
+ if p.UnencryptedHTTP2() {
+ s = append(s, "UnencryptedHTTP2")
+ }
return "{" + strings.Join(s, ",") + "}"
}