Commit d2e011d5 authored by Andrew Gerrand's avatar Andrew Gerrand

http: add test for recently fixed HTTP/1.0 keep-alive issue

R=bradfitzgo, rsc, bradfitzwork
CC=golang-dev
https://golang.org/cl/4235056
parent d7eacee6
......@@ -365,3 +365,44 @@ func TestIdentityResponse(t *testing.T) {
expectedSuffix, string(got))
}
}
// TestServeHTTP10Close verifies that HTTP/1.0 requests won't be kept alive.
func TestServeHTTP10Close(t *testing.T) {
s := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
ServeFile(w, r, "testdata/file")
}))
defer s.Close()
conn, err := net.Dial("tcp", "", s.Listener.Addr().String())
if err != nil {
t.Fatal("dial error:", err)
}
defer conn.Close()
_, err = fmt.Fprint(conn, "GET / HTTP/1.0\r\n\r\n")
if err != nil {
t.Fatal("print error:", err)
}
r := bufio.NewReader(conn)
_, err = ReadResponse(r, "GET")
if err != nil {
t.Fatal("ReadResponse error:", err)
}
success := make(chan bool)
go func() {
select {
case <-time.After(5e9):
t.Fatal("body not closed after 5s")
case <-success:
}
}()
_, err = ioutil.ReadAll(r)
if err != nil {
t.Fatal("read error:", err)
}
success <- true
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment