From bb4cf3f3514614e95b77918d3e15ff1b1f94397d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 24 Aug 2011 13:10:22 +0400 Subject: [PATCH] http: on invalid request, send 400 response Fixes #2160 R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4930049 --- src/pkg/http/server.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index cf15b5f4704..a6cb5eeafaa 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -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 }