tripper

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

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

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

type RoundTripperFunc func(*http.Request) (*http.Response, error)

RoundTripperFunc wraps a function in a RoundTripper interface similar to HandlerFunc

func (RoundTripperFunc) RoundTrip

func (f RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip calls the underlying tripper function in the RoundTripperFunc

Jump to

Keyboard shortcuts

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