Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultClient *http.Client
Functions ¶
func TimeoutHandler ¶
func TimeoutHandler(h http.Handler, dt time.Duration, code int, msg string, pool BufferPool, skipper Skipper) http.Handler
TimeoutHandler returns a http.Handler that runs h with the given time limit.
The new http.Handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler responds with the given http status code and the given message in its body. (If code is 0, http.StatusServiceUnavailable will be sent; If msg is empty, a suitable default message will be sent.) pool can be nil, and if it is nil, we use new(bytes.Buffer) to get bytes.Buffer every times. After such a timeout, writes by h to its http.ResponseWriter will return http.ErrHandlerTimeout.
TimeoutHandler buffers all http.Handler writes to memory and does not support the http.Hijacker or http.Flusher interfaces.
Types ¶
type BufferPool ¶
A BufferPool is an interface for getting and returning temporary bytes.Buffer.