diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-11-10 22:49:16 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-11-10 23:09:19 +0000 |
| commit | 9997545a8626bf1a73002f44a7b7538988da4e76 (patch) | |
| tree | 1cf62adaaf45da87830a6366bccfb3047b76ec6b /src/net/http/server.go | |
| parent | 1c54119315d9f3bd9212c01db2fd4653314959e0 (diff) | |
| download | go-9997545a8626bf1a73002f44a7b7538988da4e76.tar.xz | |
net/http: add ErrAbortHandler, make Server quiet if used as panic value
Add an explicit way for Handlers to abort their response to the client
and also not spam their error log with stack traces.
panic(nil) also worked in the past (for http1 at least), so continue
to make that work (and test it). But ErrAbortHandler is more explicit.
Updates #17790 (needs http2 updates also)
Change-Id: Ib1456905b27e2ae8cf04c0983dc73e314a4a751e
Reviewed-on: https://go-review.googlesource.com/33099
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/server.go')
| -rw-r--r-- | src/net/http/server.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go index 90e7233587..2bc71c7dd5 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -1674,11 +1674,17 @@ type badRequestError string func (e badRequestError) Error() string { return "Bad Request: " + string(e) } +// ErrAbortHandler is a sentinel panic value to abort a handler. +// While any panic from ServeHTTP aborts the response to the client, +// panicking with ErrAbortHandler also suppresses logging of a stack +// trace to the server's error log. +var ErrAbortHandler = errors.New("net/http: abort Handler") + // Serve a new connection. func (c *conn) serve(ctx context.Context) { c.remoteAddr = c.rwc.RemoteAddr().String() defer func() { - if err := recover(); err != nil { + if err := recover(); err != nil && err != ErrAbortHandler { const size = 64 << 10 buf := make([]byte, size) buf = buf[:runtime.Stack(buf, false)] |
