1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:10:04 -07:00

http: on invalid request, send 400 response

Fixes #2160

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4930049
This commit is contained in:
Brad Fitzpatrick 2011-08-24 13:10:22 +04:00
parent 4a4fa38d0e
commit bb4cf3f351

View File

@ -565,14 +565,18 @@ func (c *conn) serve() {
for {
w, err := c.readRequest()
if err != nil {
msg := "400 Bad Request"
if err == errTooLarge {
// Their HTTP client may or may not be
// able to read this if we're
// responding to them and hanging up
// while they're still writing their
// request. Undefined behavior.
fmt.Fprintf(c.rwc, "HTTP/1.1 400 Request Too Large\r\n\r\n")
msg = "400 Request Too Large"
} else if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
break // Don't reply
}
fmt.Fprintf(c.rwc, "HTTP/1.1 %s\r\n\r\n", msg)
break
}