http2: Ignore Keep-Alive header in requests
Adds Keep-Alive to the list of ignored headers in encodeHeaders
as required in the HTTP/2 spec (section 8.1.2.2) and adds a test
to check this.
Fixes golang/go#15085
Change-Id: Ie4624680c5de1f13eb94fa58a2d5d67a02634df3
Reviewed-on: https://go-review.googlesource.com/21482
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/http2/transport.go b/http2/transport.go
index 52ee68d..b5907da 100644
--- a/http2/transport.go
+++ b/http2/transport.go
@@ -945,14 +945,11 @@
// Host is :authority, already sent.
// Content-Length is automatic, set below.
continue
- case "connection", "proxy-connection", "transfer-encoding", "upgrade":
+ case "connection", "proxy-connection", "transfer-encoding", "upgrade", "keep-alive":
// Per 8.1.2.2 Connection-Specific Header
// Fields, don't send connection-specific
- // fields. We deal with these earlier in
- // RoundTrip, deciding whether they're
- // error-worthy, but we don't want to mutate
- // the user's *Request so at this point, just
- // skip over them at this point.
+ // fields. We have already checked if any
+ // are error-worthy so just ignore the rest.
continue
case "user-agent":
// Match Go's http1 behavior: at most one
diff --git a/http2/transport_test.go b/http2/transport_test.go
index 07598b2..bcc2a5f 100644
--- a/http2/transport_test.go
+++ b/http2/transport_test.go
@@ -1642,6 +1642,11 @@
value: []string{"123"},
want: "Accept-Encoding,User-Agent",
},
+ {
+ key: "Keep-Alive",
+ value: []string{"doop"},
+ want: "Accept-Encoding,User-Agent",
+ },
}
for _, tt := range tests {