mirror of
https://github.com/golang/go
synced 2024-11-19 22:44:45 -07:00
http: add test for recently fixed HTTP/1.0 keep-alive issue
R=bradfitzgo, rsc, bradfitzwork CC=golang-dev https://golang.org/cl/4235056
This commit is contained in:
parent
d7eacee603
commit
d2e011d518
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user