aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/server.go
diff options
context:
space:
mode:
authorAnmol Sethi <hi@nhooyr.io>2020-10-24 00:40:41 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2020-12-01 19:47:12 +0000
commit50b16f9de590822a04ec8d6cbac476366c1bde32 (patch)
treefb46c24ff85b7588e475de44092b1284f58c46fa /src/net/http/server.go
parent212d385a2f723a8dd5e7d2e83efb478ddd139349 (diff)
downloadgo-50b16f9de590822a04ec8d6cbac476366c1bde32.tar.xz
net/http: allow upgrading non keepalive connections
If one was using http.Transport with DisableKeepAlives and trying to upgrade a connection against net/http's Server, the Server would not allow a "Connection: Upgrade" header to be written and instead override it to "Connection: Close" which would break the handshake. This change ensures net/http's Server does not override the connection header for successful protocol switch responses. Fixes #36381. Change-Id: I882aad8539e6c87ff5f37c20e20b3a7fa1a30357 GitHub-Last-Rev: dc0de83201dc26236527b68bd49dffc53dd0389b GitHub-Pull-Request: golang/go#36382 Reviewed-on: https://go-review.googlesource.com/c/go/+/213277 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/server.go')
-rw-r--r--src/net/http/server.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go
index 6c7d281705..102e893d5f 100644
--- a/src/net/http/server.go
+++ b/src/net/http/server.go
@@ -1468,7 +1468,13 @@ func (cw *chunkWriter) writeHeader(p []byte) {
return
}
- if w.closeAfterReply && (!keepAlivesEnabled || !hasToken(cw.header.get("Connection"), "close")) {
+ // Only override the Connection header if it is not a successful
+ // protocol switch response and if KeepAlives are not enabled.
+ // See https://golang.org/issue/36381.
+ delConnectionHeader := w.closeAfterReply &&
+ (!keepAlivesEnabled || !hasToken(cw.header.get("Connection"), "close")) &&
+ !isProtocolSwitchResponse(w.status, header)
+ if delConnectionHeader {
delHeader("Connection")
if w.req.ProtoAtLeast(1, 1) {
setHeader.connection = "close"