From: Emmanuel Odeke Date: Wed, 24 May 2017 01:40:52 +0000 (-0600) Subject: net/http: polish gzip case insensitive test X-Git-Tag: go1.9beta1~173 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=59096edb4aa4a43e984439682cc9b379a1d0c2c0;p=gostls13.git 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 Reviewed-by: Brad Fitzpatrick --- diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index a5ed5c4693..c516380990 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -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()