mirror of
https://github.com/golang/go
synced 2024-11-12 02:10:21 -07:00
net/http: send one Transfer-Encoding header when "chunked" set manually
Fixes #15960 Change-Id: I7503f6ede33e6a1a93cee811d40f7b297edf47bc Reviewed-on: https://go-review.googlesource.com/23811 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
a871464e5a
commit
f9b4556de0
@ -4166,6 +4166,20 @@ func testServerContext_ServerContextKey(t *testing.T, h2 bool) {
|
||||
res.Body.Close()
|
||||
}
|
||||
|
||||
// https://golang.org/issue/15960
|
||||
func TestHandlerSetTransferEncodingChunked(t *testing.T) {
|
||||
defer afterTest(t)
|
||||
ht := newHandlerTest(HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
w.Header().Set("Transfer-Encoding", "chunked")
|
||||
w.Write([]byte("hello"))
|
||||
}))
|
||||
resp := ht.rawResponse("GET / HTTP/1.1\nHost: foo")
|
||||
const hdr = "Transfer-Encoding: chunked"
|
||||
if n := strings.Count(resp, hdr); n != 1 {
|
||||
t.Errorf("want 1 occurrence of %q in response, got %v\nresponse: %v", hdr, n, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkClientServer(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.StopTimer()
|
||||
|
@ -1147,6 +1147,7 @@ func (cw *chunkWriter) writeHeader(p []byte) {
|
||||
// to avoid closing the connection at EOF.
|
||||
cw.chunking = true
|
||||
setHeader.transferEncoding = "chunked"
|
||||
delHeader("Transfer-Encoding")
|
||||
}
|
||||
} else {
|
||||
// HTTP version < 1.1: cannot do chunked transfer
|
||||
|
Loading…
Reference in New Issue
Block a user