Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidRequest is returned if a given HTTP request is invalid and cannot be performed. ErrInvalidRequest = errors.New("invalid http request") // ErrInvalidNetwork is returned if the request would not be performed over TCP ErrInvalidNetwork = errors.New("invalid network type") // ErrReservedAddr is returned if a dialed address resolves to an IP within a blocked or reserved net. ErrReservedAddr = errors.New("dial within blocked / reserved IP range") // ErrBodyTooLarge is returned when a received response body is above predefined limit (default 40MB). ErrBodyTooLarge = errors.New("body size too large") )
Functions ¶
func SafeIP ¶ added in v0.10.0
SafeIP returns whether ip is an IPv4/6 address in a non-reserved, public range.
func ValidateRequest ¶
ValidateRequest performs the same request validation logic found in the default net/http.Transport{}.roundTrip() function, but pulls it out into this separate function allowing validation errors to be wrapped under a single error type.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an underlying http.Client{} to provide the following:
- setting a maximum received request body size, returning error on large content lengths, and using a limited reader in all other cases to protect against forged / unknown content-lengths
- protection from server side request forgery (SSRF) by only dialing out to known public IP prefixes, configurable with allows/blocks
- retry-backoff logic for error temporary HTTP error responses
- optional request signing
- request logging
func (*Client) Do ¶
Do will essentially perform http.Client{}.Do() with retry-backoff functionality.
type Config ¶
type Config struct { // MaxOpenConnsPerHost limits the max // number of open connections to a host. MaxOpenConnsPerHost int // AllowRanges allows outgoing // communications to given IP nets. AllowRanges []netip.Prefix // BlockRanges blocks outgoing // communiciations to given IP nets. BlockRanges []netip.Prefix // TLSInsecureSkipVerify can be set to true to // skip validation of remote TLS certificates. // // THIS SHOULD BE USED FOR TESTING ONLY, IF YOU // TURN THIS ON WHILE RUNNING IN PRODUCTION YOU // ARE LEAVING YOUR SERVER WIDE OPEN TO ATTACKS! TLSInsecureSkipVerify bool // MaxIdleConns: see http.Transport{}.MaxIdleConns. MaxIdleConns int // ReadBufferSize: see http.Transport{}.ReadBufferSize. ReadBufferSize int // WriteBufferSize: see http.Transport{}.WriteBufferSize. WriteBufferSize int // MaxBodySize determines the maximum fetchable body size. MaxBodySize int64 // Timeout: see http.Client{}.Timeout. Timeout time.Duration // DisableCompression: see http.Transport{}.DisableCompression. DisableCompression bool }
Config provides configuration details for setting up a new instance of httpclient.Client{}. Within are a subset of the configuration values passed to initialized http.Transport{} and http.Client{}, along with httpclient.Client{} specific.
type Request ¶ added in v0.16.0
type Request struct { // log fields. log.Entry // underlying request. *http.Request // contains filtered or unexported fields }
Request wraps an HTTP request to add our own retry / backoff.
func WrapRequest ¶ added in v0.16.0
WrapRequest wraps an existing http.Request within our own httpclient.Request with retry / backoff tracking.