From: Kenny Grant Date: Sun, 27 Sep 2015 13:53:18 +0000 (+0100) Subject: net/http: add response body to 413 and 400 errors X-Git-Tag: go1.6beta1~910 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4a6326e7b5f326e6079073fb843b4ab096cbf652;p=gostls13.git net/http: add response body to 413 and 400 errors The existing serve() method returns a zero-length response body when it encounters an error, which results in a blank page and no visible error in browsers. This change sends a response body explaining the error for display in browsers. Fixes #12745 Change-Id: I9dc3b95ad88cb92c18ced51f6b52bd3b2c1b974c Reviewed-on: https://go-review.googlesource.com/15018 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/net/http/server.go b/src/net/http/server.go index f525815ac6..0bdc9b685c 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -1339,7 +1339,7 @@ func (c *conn) serve() { // responding to them and hanging up // while they're still writing their // request. Undefined behavior. - io.WriteString(c.rwc, "HTTP/1.1 413 Request Entity Too Large\r\n\r\n") + io.WriteString(c.rwc, "HTTP/1.1 413 Request Entity Too Large\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n413 Request Entity Too Large") c.closeWriteAndWait() break } else if err == io.EOF { @@ -1347,7 +1347,7 @@ func (c *conn) serve() { } else if neterr, ok := err.(net.Error); ok && neterr.Timeout() { break // Don't reply } - io.WriteString(c.rwc, "HTTP/1.1 400 Bad Request\r\n\r\n") + io.WriteString(c.rwc, "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n400 Bad Request") break }