Documentation ¶
Index ¶
- Variables
- func DefaultClient() *http.Client
- func DefaultHTTPClient(timeout time.Duration) *http.Client
- func DefaultPooledClient() *http.Client
- func Discard(req *Request, resp *http.Response, respReadLimit int64)
- func NoKeepAliveTransport() *http.Transport
- func PassthroughErrorHandler(resp *http.Response, err error, _ int) (*http.Response, error)
- func PooledTransport() *http.Transport
- type CheckRetry
- type Client
- func (c *Client) Do(req *Request) (*http.Response, error)
- func (c *Client) Get(url string) (*http.Response, error)
- func (c *Client) Head(url string) (*http.Response, error)
- func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error)
- func (c *Client) PostForm(url string, data url.Values) (*http.Response, error)
- type ErrorHandler
- type LenReader
- type Metrics
- type Options
- type ReaderFunc
- type Request
- type RequestLogHook
- type ResponseLogHook
- type RetryStrategy
Constants ¶
This section is empty.
Variables ¶
var DefaultOptionsSingle = Options{ RetryWaitMin: 1 * time.Second, RetryWaitMax: 30 * time.Second, Timeout: 30 * time.Second, RetryMax: 5, RespReadLimit: 4096, KillIdleConn: false, }
Default options for targeting a single host.
var DefaultOptionsSpraying = Options{ RetryWaitMin: 1 * time.Second, RetryWaitMax: 30 * time.Second, Timeout: 30 * time.Second, RetryMax: 5, RespReadLimit: 4096, KillIdleConn: true, }
Default options for spraying multiple hosts.
Functions ¶
func DefaultClient ¶
DefaultClient creates a new http.Client with disabled idle connections and keepalives.
func DefaultHTTPClient ¶
DefaultHTTPClient creates an HTTP client with a default timeout.
func DefaultPooledClient ¶
DefaultPooledClient returns an http.Client with a pooled transport for connection reuse.
func Discard ¶
Discard discards the response body and closes the underlying connection. It reads up to RespReadLimit bytes from the response body to ensure connection reuse. If an error occurs during reading, it increments the DrainErrors metric.
func NoKeepAliveTransport ¶
HostSprayingTransport returns a new http.Transport with disabled idle connections and keepalives.
func PassthroughErrorHandler ¶
PassthroughErrorHandler directly passes through net/http errors for the final request.
func PooledTransport ¶
PooledTransport returns a new http.Transport for connection reuse.
Types ¶
type CheckRetry ¶
CheckRetry defines a policy for retrying requests based on the response and error.
func DefaultRetryPolicy ¶
func DefaultRetryPolicy() CheckRetry
DefaultRetryPolicy retries on connection errors and server errors.
func HostSprayRetryPolicy ¶
func HostSprayRetryPolicy() CheckRetry
HostSprayRetryPolicy retries on connection and server errors for host-spraying use cases.
type Client ¶
type Client struct { HTTPClient *http.Client RequestLogHook RequestLogHook ResponseLogHook ResponseLogHook ErrorHandler ErrorHandler CheckRetry CheckRetry RetryStrategy RetryStrategy // contains filtered or unexported fields }
Client wraps an HTTP client with retry and retryStrategy logic.
func NewWithHTTPClient ¶
NewWithHTTPClient initializes a Client with a custom HTTP client.
type ErrorHandler ¶
ErrorHandler handles retries exhaustion and returns custom responses.
type LenReader ¶
type LenReader interface {
Len() int
}
LenReader interface defines a method to get the length of a reader.
type Options ¶
type Options struct { RetryWaitMin time.Duration RetryWaitMax time.Duration Timeout time.Duration RetryMax int RespReadLimit int64 KillIdleConn bool }
Options defines retryable settings for the HTTP client.
type ReaderFunc ¶
ReaderFunc defines a function type for creating readers.
type Request ¶
Request wraps HTTP request metadata for retries.
func FromRequest ¶
FromRequest wraps an http.Request into a retryable Request.
func FromRequestWithTrace ¶
FromRequestWithTrace wraps an http.Request into a retryable Request with trace enabled.
func NewRequest ¶
NewRequest creates a new wrapped request.
func NewRequestWithContext ¶
func NewRequestWithContext(ctx context.Context, method, url string, body interface{}) (*Request, error)
NewRequestWithContext creates a new wrapped request with a context.
type RequestLogHook ¶
RequestLogHook allows executing custom logic before each retry.
type ResponseLogHook ¶
ResponseLogHook allows executing custom logic after each HTTP request.
type RetryStrategy ¶
RetryStrategy defines how long to wait between retries.
func DefaultRetryStrategy ¶
func DefaultRetryStrategy() RetryStrategy
DefaultRetryStrategy implements exponential retryStrategy based on attempt count, bounded by min and max durations.
func ExponentialRandomizedRetryStrategy ¶
func ExponentialRandomizedRetryStrategy() RetryStrategy
ExponentialRandomizedRetryStrategy adds randomized to exponential retryStrategy.
func LinearRandomizedRetryStrategy ¶
func LinearRandomizedRetryStrategy() RetryStrategy
LinearRandomizedRetryStrategy adds random randomized to linear retryStrategy.
func RandomizedFullRetryStrategy ¶
func RandomizedFullRetryStrategy() RetryStrategy
RandomizedFullRetryStrategy implements capped exponential retryStrategy with full randomized.