http

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type BufferPool interface {
	Get() *bytes.Buffer
	Put(*bytes.Buffer)
}

A BufferPool is an interface for getting and returning temporary bytes.Buffer.

type Skipper

type Skipper func(*http.Request) bool

Jump to

Keyboard shortcuts

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