Skip to content

Commit 0a5dcdd

Browse files
neildgopherbot
authored andcommitted
http2: disable extended CONNECT by default
Browsers interpret a server advertising extended CONNECT support as indicating the server supports WebSockets-over-HTTP/2. However, WebSocket-over-HTTP/2 requires support from both the HTTP implementation and the WebSocket implementation, and existing Go WebSocket packages don't support HTTP/2. Disable extended CONNECT support by default, since advertising it is a non-backwards-compatible change. For golang/go#71128 For golang/go#49918 Change-Id: Ie7d3ee2cd48124836a00bad320752e78719ffc46 Reviewed-on: https://go-review.googlesource.com/c/net/+/641475 Auto-Submit: Damien Neil <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 03179ce commit 0a5dcdd

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

http2/http2.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@ import (
3434
)
3535

3636
var (
37-
VerboseLogs bool
38-
logFrameWrites bool
39-
logFrameReads bool
40-
inTests bool
41-
disableExtendedConnectProtocol bool
37+
VerboseLogs bool
38+
logFrameWrites bool
39+
logFrameReads bool
40+
inTests bool
41+
42+
// Enabling extended CONNECT by causes browsers to attempt to use
43+
// WebSockets-over-HTTP/2. This results in problems when the server's websocket
44+
// package doesn't support extended CONNECT.
45+
//
46+
// Disable extended CONNECT by default for now.
47+
//
48+
// Issue #71128.
49+
disableExtendedConnectProtocol = true
4250
)
4351

4452
func init() {
@@ -51,8 +59,8 @@ func init() {
5159
logFrameWrites = true
5260
logFrameReads = true
5361
}
54-
if strings.Contains(e, "http2xconnect=0") {
55-
disableExtendedConnectProtocol = true
62+
if strings.Contains(e, "http2xconnect=1") {
63+
disableExtendedConnectProtocol = false
5664
}
5765
}
5866

http2/http2_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ func TestNoUnicodeStrings(t *testing.T) {
284284
}
285285
}
286286

287+
// setForTest sets *p = v, and restores its original value in t.Cleanup.
288+
func setForTest[T any](t *testing.T, p *T, v T) {
289+
orig := *p
290+
t.Cleanup(func() {
291+
*p = orig
292+
})
293+
*p = v
294+
}
295+
287296
// must returns v if err is nil, or panics otherwise.
288297
func must[T any](v T, err error) T {
289298
if err != nil {

http2/transport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5856,7 +5856,7 @@ func TestTransportTLSNextProtoConnImmediateFailureUnused(t *testing.T) {
58565856
}
58575857

58585858
func TestExtendedConnectClientWithServerSupport(t *testing.T) {
5859-
disableExtendedConnectProtocol = false
5859+
setForTest(t, &disableExtendedConnectProtocol, false)
58605860
ts := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
58615861
if r.Header.Get(":protocol") != "extended-connect" {
58625862
t.Fatalf("unexpected :protocol header received")
@@ -5892,7 +5892,7 @@ func TestExtendedConnectClientWithServerSupport(t *testing.T) {
58925892
}
58935893

58945894
func TestExtendedConnectClientWithoutServerSupport(t *testing.T) {
5895-
disableExtendedConnectProtocol = true
5895+
setForTest(t, &disableExtendedConnectProtocol, true)
58965896
ts := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
58975897
io.Copy(w, r.Body)
58985898
})

0 commit comments

Comments
 (0)