Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBodyTooLarge = errors.New("body size too large")
ErrBodyTooLarge is returned when a received response body is above predefined limit (default 40MB).
var ErrInvalidNetwork = errors.New("invalid network type")
ErrInvalidNetwork is returned if the request would not be performed over TCP
var ErrInvalidRequest = errors.New("invalid http request")
ErrInvalidRequest is returned if a given HTTP request is invalid and cannot be performed.
var ErrReservedAddr = errors.New("dial within blocked / reserved IP range")
ErrReservedAddr is returned if a dialed address resolves to an IP within a blocked or reserved net.
Functions ¶
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
- limit number of concurrent requests, else blocking until a slot is available (context channels still respected)
func (*Client) Do ¶
Do will perform given request when an available slot in the queue is available, and block until this time. For returned values, this follows the same semantics as the standard http.Client{}.Do() implementation except that response body will be wrapped by an io.LimitReader() to limit response body sizes.
type Config ¶
type Config struct { // MaxOpenConnsPerHost limits the max number of open connections to a host. MaxOpenConnsPerHost int // 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 // AllowRanges allows outgoing communications to given IP nets. AllowRanges []netip.Prefix // BlockRanges blocks outgoing communiciations to given IP nets. BlockRanges []netip.Prefix }
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.