Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTimeoutHandler ¶ added in v0.26.0
func NewTimeoutHandler(h http.Handler, msg string, timeoutFunc TimeoutFunc, logger *zap.SugaredLogger) http.Handler
NewTimeoutHandler returns a Handler that runs `h` with the given timeout in which the first byte of the response must be written, and with the given idle timeout
The new Handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler responds with a 504 Gateway Timeout error and the given message in its body. (If msg is empty, a suitable default message will be sent.) After such a timeout, writes by h to its ResponseWriter will return ErrHandlerTimeout.
A panic from the underlying handler is propagated as-is to be able to make use of custom panic behavior by HTTP handlers. See https://golang.org/pkg/net/http/#Handler.
The implementation is largely inspired by http.TimeoutHandler.
Types ¶
type HijackTracker ¶ added in v0.49.0
type HijackTracker struct {
Handler http.Handler
PollInterval time.Duration
// contains filtered or unexported fields
}
HijackTracker is used to track Websocket Connections Go net/http by default will not manage connections that are hijacked. Thus http.Server::Shutdown will not wait for those connections to finish.
What this handler does is track inflight requests using a counter and drain will loop and poll until all the requests are finished.
func (*HijackTracker) Drain ¶ added in v0.49.0
func (s *HijackTracker) Drain(ctx context.Context) error
Drain should be called after http.Server:Shutdown returns
func (*HijackTracker) ServeHTTP ¶ added in v0.49.0
func (s *HijackTracker) ServeHTTP(w http.ResponseWriter, r *http.Request)