mirror of
https://github.com/golang/go
synced 2024-11-13 17:50:23 -07:00
http: don't send a 400 Bad Request after a client shutdown
Fixes #2312 R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/5143049
This commit is contained in:
parent
32d1e46058
commit
58a5f1e84f
@ -987,6 +987,38 @@ func TestRequestBodyLimit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestClientWriteShutdown tests that if the client shuts down the write
|
||||||
|
// side of their TCP connection, the server doesn't send a 400 Bad Request.
|
||||||
|
func TestClientWriteShutdown(t *testing.T) {
|
||||||
|
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {}))
|
||||||
|
defer ts.Close()
|
||||||
|
conn, err := net.Dial("tcp", ts.Listener.Addr().String())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Dial: %v", err)
|
||||||
|
}
|
||||||
|
err = conn.(*net.TCPConn).CloseWrite()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Dial: %v", err)
|
||||||
|
}
|
||||||
|
donec := make(chan bool)
|
||||||
|
go func() {
|
||||||
|
defer close(donec)
|
||||||
|
bs, err := ioutil.ReadAll(conn)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ReadAll: %v", err)
|
||||||
|
}
|
||||||
|
got := string(bs)
|
||||||
|
if got != "" {
|
||||||
|
t.Errorf("read %q from server; want nothing", got)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-donec:
|
||||||
|
case <-time.After(10e9):
|
||||||
|
t.Fatalf("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type errorListener struct {
|
type errorListener struct {
|
||||||
errs []os.Error
|
errs []os.Error
|
||||||
}
|
}
|
||||||
|
@ -572,6 +572,8 @@ func (c *conn) serve() {
|
|||||||
// while they're still writing their
|
// while they're still writing their
|
||||||
// request. Undefined behavior.
|
// request. Undefined behavior.
|
||||||
msg = "413 Request Entity Too Large"
|
msg = "413 Request Entity Too Large"
|
||||||
|
} else if err == io.ErrUnexpectedEOF {
|
||||||
|
break // Don't reply
|
||||||
} else if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
|
} else if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
|
||||||
break // Don't reply
|
break // Don't reply
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user