]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: polish gzip case insensitive test
authorEmmanuel Odeke <emm.odeke@gmail.com>
Wed, 24 May 2017 01:40:52 +0000 (19:40 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 24 May 2017 02:44:51 +0000 (02:44 +0000)
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>
src/net/http/transport_test.go

index a5ed5c4693da7a183f121e6a663a3da0ac2fdd72..c5163809901997d138ba0b1f3fa479a350794630 100644 (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()