Browse Source

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>
Roland Shoemaker 9 years ago
parent
commit
024ed629fd
2 changed files with 8 additions and 6 deletions
  1. 3 6
      http2/transport.go
  2. 5 0
      http2/transport_test.go

+ 3 - 6
http2/transport.go

@@ -945,14 +945,11 @@ func (cc *ClientConn) encodeHeaders(req *http.Request, addGzipHeader bool, trail
 			// 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

+ 5 - 0
http2/transport_test.go

@@ -1642,6 +1642,11 @@ func TestTransportRejectsConnHeaders(t *testing.T) {
 			value: []string{"123"},
 			want:  "Accept-Encoding,User-Agent",
 		},
+		{
+			key:   "Keep-Alive",
+			value: []string{"doop"},
+			want:  "Accept-Encoding,User-Agent",
+		},
 	}
 
 	for _, tt := range tests {