Documentation
¶
Overview ¶
Package shed implements client and server middleware to propagate and respect client timeouts between services.
Index ¶
- Constants
- func Client(c *http.Client, opts ...RoundTripperOpt) *http.Client
- func DefaultTimeoutMiddleware(n http.Handler, timeout func(*http.Request) time.Duration) http.Handler
- func PropagateMiddleware(n http.Handler, opts ...PropagateMiddlewareOpt) http.Handler
- func RoundTripper(n http.RoundTripper, opts ...RoundTripperOpt) http.RoundTripper
- type PropagateMiddlewareOpt
- type RoundTripperOpt
Constants ¶
const ( // Header contains the header key expected to be set by incoming requests // in order to propagate timeouts across the network, it is expected to be // a string parseable into an int64 which represents the timeout of the // client in milliseconds. Header = "X-Client-Timeout-Ms" )
Variables ¶
This section is empty.
Functions ¶
func Client ¶
func Client(c *http.Client, opts ...RoundTripperOpt) *http.Client
Client builds a new *http.Client from the given *http.Client, wrapping the given client's Transport using RoundTripper.
func DefaultTimeoutMiddleware ¶
func DefaultTimeoutMiddleware(n http.Handler, timeout func(*http.Request) time.Duration) http.Handler
DefaultTimeoutMiddleware wraps the given handler with a default context deadline propagated via the request context.
The timeout function can be used to have dynamic request based upper bounds for requests. If this function returns a time.Duration that is not strictly greater than 0, no timeout will be set.
func PropagateMiddleware ¶
func PropagateMiddleware(n http.Handler, opts ...PropagateMiddlewareOpt) http.Handler
PropagateMiddleware builds a new http.Handler middleware which sets a context timeout on incoming requests if the client has propagated its timeout via the `X-Client-Timeout-Ms` header.
func RoundTripper ¶
func RoundTripper(n http.RoundTripper, opts ...RoundTripperOpt) http.RoundTripper
RoundTripper builds a new http.RoundTripper which propagates context deadlines over the network via the `X-Client-Timeout-Ms` request header.
Types ¶
type PropagateMiddlewareOpt ¶
type PropagateMiddlewareOpt func(*propagateMiddleware)
PropagateMiddlewareOpt is a function which can modify the behaviour of the shed middleware.
func WithDelta ¶
func WithDelta(f func(*http.Request) time.Duration) PropagateMiddlewareOpt
WithDelta allows for adjusting the timeout set by the Middleware, in order to account for time spent in the network or on various server queues.
The value returned by this function will by subtracted from the `X-Client-Timeout-Ms` value.
type RoundTripperOpt ¶ added in v0.0.4
type RoundTripperOpt func(*roundTripper)
RoundTripperOpt is a function which can modify the behaviour of the shed client transport middleware.
func WithMaxTimeout ¶ added in v0.0.4
func WithMaxTimeout(d time.Duration) RoundTripperOpt
WithMaxTimeout will set a default X-Client-Timeout-Ms if it is lower than any context.Context deadline on the request.
This is intended to be used in cases where some other timeouts are set on the client, e.g. ResponseHeaderTimeout.