Created
April 19, 2016 14:07
-
-
Save sbadame/6672153feb5a5430a0129d40b263d8e9 to your computer and use it in GitHub Desktop.
Reproduction for net/http: Response.Write has bogus Connection header after auto-ungzipped Content-Length response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net" | |
"net/http" | |
"net/http/httputil" | |
"os" | |
) | |
// A reproduction of a bug where http.transport.RoundTrip returns an http.Response | |
// that contains both "Connection: close" and "Connection: keep-alive" headers. | |
// Pass in a file with the response to parse as the first argument. | |
func main() { | |
// Minimal response to reproduce the bug. Content is a gzipped UTF-8 "FOO". | |
response, _ := ioutil.ReadFile(os.Args[1]) | |
ln, err := net.Listen("tcp", ":8080") | |
if err != nil { | |
// handle error | |
} | |
go func() { | |
for { | |
conn, err := ln.Accept() | |
if err != nil { | |
// handle error | |
} | |
conn.Write(response) | |
} | |
}() | |
t := &http.Transport{} | |
req, _ := http.NewRequest("GET", "http://localhost:8080", nil) | |
res, rt_err := t.RoundTrip(req) | |
if rt_err != nil { | |
log.Fatalf("ERROR RT: %v\n", rt_err) | |
} | |
buf, err := httputil.DumpResponse(res, false) | |
if err != nil { | |
log.Fatalf("ERROR DR: %v\n", err) | |
} | |
fmt.Printf("http.Transport.RoundTrip response: %s\n", buf) | |
res, rt_err = http.DefaultClient.Do(req) | |
if rt_err != nil { | |
log.Fatalf("ERROR RT: %v\n", rt_err) | |
} | |
buf, err = httputil.DumpResponse(res, false) | |
if err != nil { | |
log.Fatalf("ERROR DR: %v\n", err) | |
} | |
fmt.Printf("http.DefaultClient.Do Response: %s\n", buf) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP/1.1 200 OK | |
Content-Encoding: gzip | |
Content-Length: 23 | |
Connection: keep-alive | |
Keep-Alive: timeout=7200 | |
\8B\00\00\00\00\00\00\00s\F3\F7\00\AB'\D4\00\00\00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment