1
0
mirror of https://github.com/golang/go synced 2024-11-23 07:50:05 -07:00

net/http: pass through server side Transfer-Encoding headers

Fixes #16063

Change-Id: I2e8695beb657b0aef067e83f086828d8857787ed
Reviewed-on: https://go-review.googlesource.com/24130
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:
Andrew Gerrand 2016-06-15 10:52:42 +10:00
parent c4692da923
commit 0ec62565f9
2 changed files with 23 additions and 1 deletions

View File

@ -9,6 +9,7 @@ package http_test
import (
"bufio"
"bytes"
"compress/gzip"
"context"
"crypto/tls"
"encoding/json"
@ -4200,6 +4201,24 @@ func TestHandlerSetTransferEncodingChunked(t *testing.T) {
}
}
// https://golang.org/issue/16063
func TestHandlerSetTransferEncodingGzip(t *testing.T) {
defer afterTest(t)
ht := newHandlerTest(HandlerFunc(func(w ResponseWriter, r *Request) {
w.Header().Set("Transfer-Encoding", "gzip")
gz := gzip.NewWriter(w)
gz.Write([]byte("hello"))
gz.Close()
}))
resp := ht.rawResponse("GET / HTTP/1.1\nHost: foo")
for _, v := range []string{"gzip", "chunked"} {
hdr := "Transfer-Encoding: " + v
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()

View File

@ -1147,7 +1147,10 @@ func (cw *chunkWriter) writeHeader(p []byte) {
// to avoid closing the connection at EOF.
cw.chunking = true
setHeader.transferEncoding = "chunked"
delHeader("Transfer-Encoding")
if hasTE && te == "chunked" {
// We will send the chunked Transfer-Encoding header later.
delHeader("Transfer-Encoding")
}
}
} else {
// HTTP version < 1.1: cannot do chunked transfer