Skip to content

Commit 4a6326e

Browse files
kennygrantbradfitz
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 9dd81d6 commit 4a6326e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/net/http/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,15 +1339,15 @@ func (c *conn) serve() {
13391339
// responding to them and hanging up
13401340
// while they're still writing their
13411341
// request. Undefined behavior.
1342-
io.WriteString(c.rwc, "HTTP/1.1 413 Request Entity Too Large\r\n\r\n")
1342+
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")
13431343
c.closeWriteAndWait()
13441344
break
13451345
} else if err == io.EOF {
13461346
break // Don't reply
13471347
} else if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
13481348
break // Don't reply
13491349
}
1350-
io.WriteString(c.rwc, "HTTP/1.1 400 Bad Request\r\n\r\n")
1350+
io.WriteString(c.rwc, "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n400 Bad Request")
13511351
break
13521352
}
13531353

0 commit comments

Comments
 (0)