Skip to content

Commit 59096ed

Browse files
odeke-embradfitz
authored andcommitted
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 <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 51b2213 commit 59096ed

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/net/http/transport_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,12 +2907,12 @@ func TestTransportContentEncodingCaseInsensitive(t *testing.T) {
29072907
for _, ce := range []string{"gzip", "GZIP"} {
29082908
ce := ce
29092909
t.Run(ce, func(t *testing.T) {
2910-
const encodedString = "aaaa"
2910+
const encodedString = "Hello Gopher"
29112911
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
2912-
conn, _, _ := w.(Hijacker).Hijack()
2913-
fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\nContent-Encoding: %s\r\nContent-Length: 28\r\n\r\n", ce)
2914-
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"))
2915-
conn.Close()
2912+
w.Header().Set("Content-Encoding", ce)
2913+
gz := gzip.NewWriter(w)
2914+
gz.Write([]byte(encodedString))
2915+
gz.Close()
29162916
}))
29172917
defer ts.Close()
29182918

0 commit comments

Comments
 (0)