Documentation ¶
Index ¶
- func Cleanup(r *http.Response)
- type Client
- type ConstantHandler
- type Header
- func (h Header) AddTo(dst http.Header)
- func (h Header) Append(more http.Header) Header
- func (h Header) AppendHeaders(more ...string) Header
- func (h Header) AppendMap(more map[string]string) Header
- func (h Header) Extend(more Header) Header
- func (h Header) Len() int
- func (h Header) SetTo(dst http.Header)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConstantHandler ¶
type ConstantHandler struct { // StatusCode is the response code to pass to http.ResponseWriter.WriteHeader. // If this value is less than 100 (which also includes being unset), then no // response code is written which will trigger the default of http.StatusOK. StatusCode int // Header is the set of headers added to every response Header Header // ContentType is the MIME type of the Body. This will override anything written by // the Headers closure. This field has no effect if Body is not also set. If Body is // set and this field is unset, then no Content-Type header is written by this handler. // A Content-Type may still be written by other infrastructure or by the Headers closure, however. ContentType string // Body is the optional HTTP entity body. If unset, nothing is written for the response body. // A Content-Length header will be explicitly set if this field is set. Body []byte }
ConstantHandler is an http.Handler that writes a statically defined HTTP response. Very useful for testing and for default behavior.
func ConstantJSON ¶
func ConstantJSON(v interface{}) (ch ConstantHandler, err error)
ConstantJSON is a convenience for constructing a ConstantHandler that returns a static JSON message. The encoding/json package is used to marshal v.
func (ConstantHandler) ServeHTTP ¶
func (ch ConstantHandler) ServeHTTP(response http.ResponseWriter, _ *http.Request)
ServeHTTP returns the constant information in the response.
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header is a more efficient version of http.Header for situations where a number of HTTP headers are stored in memory and reused. Rather than a map, a simple list of headers is maintained in canonicalized form. This is much faster to iterate over than a map, which becomes important when the same Header is used to add headers to many requests.
A Header instance is immutable once created. The zero value is an usable, empty Header which is immutable.
func EmptyHeader ¶ added in v0.1.6
func EmptyHeader() Header
EmptyHeader returns a canonical singleton Header that is empty. Useful as a "nil" value or as a default.
func NewHeader ¶
NewHeader creates an immutable, preprocessed Header given an http.Header.
If v is empty, the canonical EmptyHeader is returned.
func NewHeaderFromMap ¶
NewHeaderFromMap creates an immutable, preprocessed Header given a simple map of string-to-string.
If v is empty, the canonical EmptyHeader is returned.
func NewHeaders ¶
NewHeaders creates an immutable, preprocessed Header given a variadic list of names and values in {name1, value1, name2, value2, ...} order. Duplicate names are allowed, which will result in multi-valued headers. If v contains an odd number of values, the last value is interpreted as a header name with a single blank value.
If v is empty, the canonical EmptyHeader is returned.
func (Header) AddTo ¶ added in v0.1.6
AddTo adds each name/value defined in this Header to the supplied http.Header.
func (Header) Append ¶ added in v0.1.6
Append returns a new Header instance with the given http.Header values appended to these header values. If more is empty, the original Header is returned.
This method does not modify the original Header.
func (Header) AppendHeaders ¶ added in v0.1.6
AppendHeaders return a new Header with the variadic slice of name/value pairs appended. If more has an odd length, the last value is assumed to be a name with a blank value. If more is empty, the original Header is returned. Duplicate names are allowed, which result in multi-valued headers.
This method does not modify the original Header.
func (Header) AppendMap ¶ added in v0.1.6
AppendMap returns a new Header instance with the given map of headers added. This function is useful in the simple cases where only single-valued headers are supported by application code. If more is empty, the original Header is returned.
This method does not modify the original Header.
func (Header) Extend ¶ added in v0.1.6
Extend returns the merger of this Header with the given Header. If this Header is empty, more is returned. If more is empty, this Header is returned. Otherwise, a new Header that is the union of the two is returned.
This method does not modify the original Header.
Directories ¶
Path | Synopsis |
---|---|
Package client provides infrastructure for build HTTP clients, including observability and logging.
|
Package client provides infrastructure for build HTTP clients, including observability and logging. |
Package erraux provides auxiliary functionality for marshaling and returning errors over HTTP.
|
Package erraux provides auxiliary functionality for marshaling and returning errors over HTTP. |
Package gate implements a simple atomic boolean that controls access to HTTP client or server functionality
|
Package gate implements a simple atomic boolean that controls access to HTTP client or server functionality |
Package httpmock provides stretchr/testify/mock integration
|
Package httpmock provides stretchr/testify/mock integration |
Package observe exposes a standard way of decorating http.ResponseWriter objects so that they can be examined by infrastructure such as logging and metrics.
|
Package observe exposes a standard way of decorating http.ResponseWriter objects so that they can be examined by infrastructure such as logging and metrics. |
Package recovery implements an http.Handler that recovers from panics, allowing configurable actions to take when a panic occurs.
|
Package recovery implements an http.Handler that recovers from panics, allowing configurable actions to take when a panic occurs. |
Package retry implements retry logic for HTTP clients.
|
Package retry implements retry logic for HTTP clients. |
Package roundtrip provides middleware and a few utility types for use with http.RoundTripper
|
Package roundtrip provides middleware and a few utility types for use with http.RoundTripper |
Package server provides extra functionality specific to HTTP servers and handlers.
|
Package server provides extra functionality specific to HTTP servers and handlers. |