From 59096edb4aa4a43e984439682cc9b379a1d0c2c0 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Tue, 23 May 2017 19:40:52 -0600 Subject: [PATCH] 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 --- src/net/http/transport_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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() -- 2.50.0