Documentation ¶
Index ¶
- Variables
- func DefaultShouldRetry(request *http.Request, response *http.Response, withDelay time.Duration) bool
- func Do(client *http.Client, request *http.Request, retries *RetryConfig, ...) (*http.Response, error)
- func NewRequest(method string, url string, body io.Reader, headers map[string]string) (*http.Request, error)
- func ParseRetryAfter(value string) time.Duration
- func SetDebug(enabled bool)
- func SetRequestor(requestor Requestor)
- type AccessConfig
- type MockRequestor
- type MockResponse
- type Requestor
- type RetryConfig
- type Trace
Constants ¶
This section is empty.
Variables ¶
var MockConnectionError = MockResponse{Status: 0, Headers: nil, Body: []byte{}, BodyRepeat: 0}
MockConnectionError mocks a connection error
Functions ¶
func DefaultShouldRetry ¶ added in v0.64.0
func DefaultShouldRetry(request *http.Request, response *http.Response, withDelay time.Duration) bool
DefaultShouldRetry is the default function for determining if a response should be retried
func Do ¶
func Do(client *http.Client, request *http.Request, retries *RetryConfig, access *AccessConfig) (*http.Response, error)
Do makes the given HTTP request using the current requestor and retry config
func NewRequest ¶ added in v0.81.0
func NewRequest(method string, url string, body io.Reader, headers map[string]string) (*http.Request, error)
NewRequest is a convenience method to create a request with the given headers
func ParseRetryAfter ¶ added in v0.64.0
ParseRetryAfter parses value of Retry-After headers which can be date or delay in seconds see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
func SetRequestor ¶
func SetRequestor(requestor Requestor)
SetRequestor sets the requestor used by Request
Types ¶
type AccessConfig ¶ added in v0.77.0
AccessConfig configures what can be accessed
func NewAccessConfig ¶ added in v0.77.0
func NewAccessConfig(resolveTimeout time.Duration, disallowedIPs []net.IP) *AccessConfig
NewAccessConfig creates a new access config
type MockRequestor ¶ added in v0.52.0
type MockRequestor struct {
// contains filtered or unexported fields
}
MockRequestor is a requestor which can be mocked with responses for given URLs
func NewMockRequestor ¶
func NewMockRequestor(mocks map[string][]MockResponse) *MockRequestor
NewMockRequestor creates a new mock requestor with the given mocks
func (*MockRequestor) Clone ¶ added in v0.54.0
func (r *MockRequestor) Clone() *MockRequestor
Clone returns a clone of this requestor
func (*MockRequestor) HasUnused ¶ added in v0.52.0
func (r *MockRequestor) HasUnused() bool
HasUnused returns true if there are unused mocks leftover
func (*MockRequestor) MarshalJSON ¶ added in v0.54.0
func (r *MockRequestor) MarshalJSON() ([]byte, error)
func (*MockRequestor) UnmarshalJSON ¶ added in v0.52.0
func (r *MockRequestor) UnmarshalJSON(data []byte) error
type MockResponse ¶ added in v0.52.0
func NewMockResponse ¶
func NewMockResponse(status int, headers map[string]string, body string) MockResponse
NewMockResponse creates a new mock response from a string
func (MockResponse) Make ¶ added in v0.52.0
func (m MockResponse) Make(request *http.Request) *http.Response
Make mocks making the given request and returning this as the response
func (*MockResponse) MarshalJSON ¶ added in v0.81.0
func (m *MockResponse) MarshalJSON() ([]byte, error)
func (*MockResponse) UnmarshalJSON ¶ added in v0.81.0
func (m *MockResponse) UnmarshalJSON(data []byte) error
type Requestor ¶
Requestor is anything that can make an HTTP request with a client
var DefaultRequestor Requestor = defaultRequestor{}
DefaultRequestor is the default HTTP requestor
type RetryConfig ¶ added in v0.64.0
type RetryConfig struct { Backoffs []time.Duration Jitter float64 ShouldRetry func(*http.Request, *http.Response, time.Duration) bool }
RetryConfig configures if and how retrying of requests happens
func NewExponentialRetries ¶ added in v0.64.1
func NewExponentialRetries(initialBackoff time.Duration, count int, jitter float64) *RetryConfig
NewExponentialRetries creates a new retry config with the given delays
func NewFixedRetries ¶ added in v0.64.1
func NewFixedRetries(backoffs ...time.Duration) *RetryConfig
NewFixedRetries creates a new retry config with the given backoffs
func (*RetryConfig) Backoff ¶ added in v0.64.1
func (r *RetryConfig) Backoff(n int) time.Duration
Backoff gets the backoff time for the nth retry
func (*RetryConfig) MaxRetries ¶ added in v0.64.1
func (r *RetryConfig) MaxRetries() int
MaxRetries gets the maximum number of retries allowed
type Trace ¶
type Trace struct { Request *http.Request RequestTrace []byte Response *http.Response ResponseTrace []byte ResponseBody []byte // response body stored separately StartTime time.Time EndTime time.Time }
Trace holds the complete trace of an HTTP request/response
func DoTrace ¶
func DoTrace(client *http.Client, request *http.Request, retries *RetryConfig, access *AccessConfig, maxBodyBytes int) (*Trace, error)
DoTrace makes the given request saving traces of the complete request and response
func (*Trace) ResponseTraceUTF8 ¶ added in v0.81.0
ResponseTraceUTF8 returns a valid UTF-8 string version of trace, substituting the body with placeholder if it isn't valid UTF-8