1
0
mirror of https://github.com/golang/go synced 2024-09-30 11:18:33 -06:00

net/http: polish gzip case insensitive test

Avoid directly using the binary of the
gzipped encoded string in the handler.

Follow up of CL 37431.

Change-Id: Idcd04acb7940e67b7a35b2d6cb163d75b0e22e04
Reviewed-on: https://go-review.googlesource.com/44008
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Emmanuel Odeke 2017-05-23 19:40:52 -06:00 committed by Brad Fitzpatrick
parent 51b22130b5
commit 59096edb4a

View File

@ -2907,12 +2907,12 @@ func TestTransportContentEncodingCaseInsensitive(t *testing.T) {
for _, ce := range []string{"gzip", "GZIP"} {
ce := ce
t.Run(ce, func(t *testing.T) {
const encodedString = "aaaa"
const encodedString = "Hello Gopher"
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
conn, _, _ := w.(Hijacker).Hijack()
fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\nContent-Encoding: %s\r\nContent-Length: 28\r\n\r\n", ce)
conn.Write([]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4a\x4c\x4c\x4c\x04\x04\x00\x00\xff\xff\x45\xe5\x98\xad\x04\x00\x00\x00"))
conn.Close()
w.Header().Set("Content-Encoding", ce)
gz := gzip.NewWriter(w)
gz.Write([]byte(encodedString))
gz.Close()
}))
defer ts.Close()