Description
Proposal Details
Similar to the previous proposals in #16542 and #25245,
I propose a per Server
opt out of panic recovering and printing.
While the automatic panic recovery was previously deemed regrettable, the above proposals declined for being somewhat backwards incompatible, especially when ErrAbortHandler
was used. Therefore, I also propose a new method for ResponseController
to cleanly close the connection, without interrupting the control flow. This allows the handler to perform any clean up necessary, which is more in line with normal Go error handling.
Glancing through the uses of panic(http.ErrAbortHandler)
on Github: search link, I assert that these are almost all in modules where the handlers and server are developed together, so it should be relatively easy for users that wish to set DisablePanicHandler = true
to also audit the handlers for any uses of panic(http.ErrAbortHandler)
.
API additions:
type Server struct{
// Disables the automatic recovery of panics
// and printing of stack traces in handlers.
// To close a connection, use [ResponseController.AbortConnection].
DisablePanicHandler bool
}
// Abort terminates the current request without sending a response.
// For HTTP/1 it closes the network connection,
// for HTTP/2 it sends a RST_STREAM. Handlers must not write to
// ResponseWriter after calling AbortConnection.
func (c *ResponseController) Abort()
cc @neild
Metadata
Metadata
Assignees
Type
Projects
Status
Incoming
Activity