handler

package
v0.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTimeToFirstByteTimeoutHandler

func NewTimeToFirstByteTimeoutHandler(h http.Handler, msg string, timeoutFunc TimeoutFunc) http.Handler

NewTimeToFirstByteTimeoutHandler returns a Handler that runs `h` with the given time limit from the timeout function in which the first byte of the response must be written.

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 TimeoutFunc

type TimeoutFunc func(req *http.Request) time.Duration

TimeoutFunc returns the timeout duration to be used by the timeout handler.

func StaticTimeoutFunc

func StaticTimeoutFunc(timeout time.Duration) TimeoutFunc

StaticTimeoutFunc returns a TimeoutFunc that always returns the same duration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL