Commit 0ec62565 authored by Andrew Gerrand's avatar Andrew Gerrand

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

Fixes #16063

Change-Id: I2e8695beb657b0aef067e83f086828d8857787ed
Reviewed-on: https://go-review.googlesource.com/24130Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c4692da9
...@@ -9,6 +9,7 @@ package http_test ...@@ -9,6 +9,7 @@ package http_test
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"compress/gzip"
"context" "context"
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
...@@ -4200,6 +4201,24 @@ func TestHandlerSetTransferEncodingChunked(t *testing.T) { ...@@ -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) { func BenchmarkClientServer(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
b.StopTimer() b.StopTimer()
......
...@@ -1147,8 +1147,11 @@ func (cw *chunkWriter) writeHeader(p []byte) { ...@@ -1147,8 +1147,11 @@ func (cw *chunkWriter) writeHeader(p []byte) {
// to avoid closing the connection at EOF. // to avoid closing the connection at EOF.
cw.chunking = true cw.chunking = true
setHeader.transferEncoding = "chunked" setHeader.transferEncoding = "chunked"
if hasTE && te == "chunked" {
// We will send the chunked Transfer-Encoding header later.
delHeader("Transfer-Encoding") delHeader("Transfer-Encoding")
} }
}
} else { } else {
// HTTP version < 1.1: cannot do chunked transfer // HTTP version < 1.1: cannot do chunked transfer
// encoding and we don't know the Content-Length so // encoding and we don't know the Content-Length so
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment