1
0
mirror of https://github.com/golang/go synced 2024-11-26 18:26:48 -07:00

net/http/httputil: do not duplicate 'Connection: close' headers

Fixes #54616.

Change-Id: I46f41bbccff7b49f26f60c1edf65acfd1701aed5
Reviewed-on: https://go-review.googlesource.com/c/go/+/425155
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
This commit is contained in:
Miguel Ángel Jimeno 2022-08-23 14:06:19 +02:00 committed by David Chase
parent d88560afd3
commit 44d057d581
2 changed files with 13 additions and 3 deletions

View File

@ -258,9 +258,6 @@ func DumpRequest(req *http.Request, body bool) ([]byte, error) {
if len(req.TransferEncoding) > 0 {
fmt.Fprintf(&b, "Transfer-Encoding: %s\r\n", strings.Join(req.TransferEncoding, ","))
}
if req.Close {
fmt.Fprintf(&b, "Connection: close\r\n")
}
err = req.Header.WriteSubset(&b, reqWriteExcludeHeaderDump)
if err != nil {

View File

@ -236,6 +236,19 @@ var dumpTests = []dumpTest{
"Transfer-Encoding: chunked\r\n" +
"Accept-Encoding: gzip\r\n\r\n",
},
// Issue 54616: request with Connection header doesn't result in duplicate header.
{
GetReq: func() *http.Request {
return mustReadRequest("GET / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
"Connection: close\r\n\r\n")
},
NoBody: true,
WantDump: "GET / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
"Connection: close\r\n\r\n",
},
}
func TestDumpRequest(t *testing.T) {