Skip to content

Commit 68c5fdd

Browse files
neildgopherbot
authored andcommitted
[internal-branch.go1.24-vendor] 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]> (cherry picked from commit 0a5dcdd) Reviewed-on: https://go-review.googlesource.com/c/net/+/642606 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent 552d8ac commit 68c5fdd

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

http2/http2.go

+15-7
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

+9
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5824,7 +5824,7 @@ func TestTransportTLSNextProtoConnImmediateFailureUnused(t *testing.T) {
58245824
}
58255825

58265826
func TestExtendedConnectClientWithServerSupport(t *testing.T) {
5827-
disableExtendedConnectProtocol = false
5827+
setForTest(t, &disableExtendedConnectProtocol, false)
58285828
ts := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
58295829
if r.Header.Get(":protocol") != "extended-connect" {
58305830
t.Fatalf("unexpected :protocol header received")
@@ -5860,7 +5860,7 @@ func TestExtendedConnectClientWithServerSupport(t *testing.T) {
58605860
}
58615861

58625862
func TestExtendedConnectClientWithoutServerSupport(t *testing.T) {
5863-
disableExtendedConnectProtocol = true
5863+
setForTest(t, &disableExtendedConnectProtocol, true)
58645864
ts := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
58655865
io.Copy(w, r.Body)
58665866
})

0 commit comments

Comments
 (0)