]> Cypherpunks repositories - gostls13.git/commitdiff
http: on invalid request, send 400 response
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 24 Aug 2011 09:10:22 +0000 (13:10 +0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 24 Aug 2011 09:10:22 +0000 (13:10 +0400)
Fixes #2160

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4930049

src/pkg/http/server.go

index cf15b5f4704fb6ba0d257ca6d2b380f3c3533a2c..a6cb5eeafaa8d198b378cf278f8302b5d6c41979 100644 (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
                }