Documentation
¶
Overview ¶
Package tripper provides utility functions for working with the http.RoundTripper interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain acts as a list of http.RoundTripper constructors. Chain is effectively immutable: once created, it will always hold the same set of constructors in the same order.
func NewChain ¶
func NewChain(constructors ...Constructor) Chain
NewChain creates a new chain, memorizing the given list of tripper constructors. New serves no other function, constructors are only called upon a call to Then().
func (Chain) Append ¶
func (c Chain) Append(constructors ...Constructor) Chain
Append extends a chain, adding the specified constructors as the last ones in the request flow.
Append returns a new chain, leaving the original one untouched.
stdChain := middleware.NewChain(m1, m2) extChain := stdChain.Append(m3, m4) // requests in stdChain go m1 -> m2 // requests in extChain go m1 -> m2 -> m3 -> m4
func (Chain) Then ¶
func (c Chain) Then(h http.RoundTripper) http.RoundTripper
Then chains the trippers and returns the final http.RoundTripper.
NewChain(m1, m2, m3).Then(h)
is equivalent to:
m1(m2(m3(h)))
When the request comes in, it will be passed to m1, then m2, then m3 and finally, the given roundtripper (assuming every tripper calls the following one).
A chain can be safely reused by calling Then() several times.
stdStack := tripper.NewChain(ratelimitTripper, csrfTripper) tracePipe = stdStack.Then(traceTripper) authPipe = stdStack.Then(authTripper)
Note that constructors are called on every call to Then() and thus several instances of the same tripper will be created when a chain is reused in this way. For proper tripper implementations, this should cause no problems.
Then() treats nil as http.DefaultTransport.
type Constructor ¶
type Constructor func(http.RoundTripper) http.RoundTripper
Constructor is a type alias for func(http.RoundTripper) http.RoundTripper
type RoundTripperFunc ¶
RoundTripperFunc wraps a function in a RoundTripper interface similar to HandlerFunc