Documentation
¶
Index ¶
- Variables
- func DelayWithJitter(baseDelay, jitter time.Duration) time.Duration
- func Sleep(baseDelay, jitter time.Duration)
- type Client
- func (c *Client) CloseIdleConnections()
- func (c *Client) Do(req *http.Request) (*Response, error)
- func (c *Client) Get(ctx context.Context, url string) (*Response, error)
- func (c *Client) GetJSON(ctx context.Context, url string, dest any) (*Response, error)
- func (c *Client) GetWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
- func (c *Client) Head(ctx context.Context, url string) (*Response, error)
- func (c *Client) HeadWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
- func (c *Client) IsAlive(ctx context.Context, url string) bool
- func (c *Client) Post(ctx context.Context, url string, body any) (*Response, error)
- func (c *Client) PostForm(ctx context.Context, requestURL string, values url.Values) (*Response, error)
- func (c *Client) PostFormWithHeaders(ctx context.Context, requestURL string, values url.Values, ...) (*Response, error)
- func (c *Client) PostJSON(ctx context.Context, url string, body any, dest any) (*Response, error)
- func (c *Client) PostWithHeaders(ctx context.Context, url string, body any, headers map[string]string) (*Response, error)
- func (c *Client) Request(ctx context.Context, method, requestURL string, body io.Reader, ...) (*Response, error)
- type Option
- func WithBlockCrossDomainRedirects() Option
- func WithDefaultHeaders(headers map[string]string) Option
- func WithHTTPProxy(proxyURL string) Option
- func WithMaxRedirects(n int) Option
- func WithMaxResponseBodyBytes(n int64) Option
- func WithRedirectTracking() Option
- func WithSOCKSProxy(proxyURL string) Option
- func WithTLSVerify(verify bool) Option
- func WithTimeout(d time.Duration) Option
- func WithTransport(transport *http.Transport) Option
- type Options
- type RedirectHop
- type Response
Constants ¶
This section is empty.
Variables ¶
var ErrResponseBodyTooLarge = errors.New("HTTP response body exceeds configured limit")
ErrResponseBodyTooLarge indicates that a configured response body limit was exceeded.
Functions ¶
func DelayWithJitter ¶
DelayWithJitter returns a duration with random jitter applied. The result is between baseDelay and baseDelay + jitter.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps http.Client with Method-specific defaults and helpers.
func (*Client) CloseIdleConnections ¶ added in v0.2.0
func (c *Client) CloseIdleConnections()
CloseIdleConnections closes this client's idle connections without interrupting active requests. The transport supplied to WithTransport is not affected.
func (*Client) GetWithHeaders ¶
func (c *Client) GetWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
GetWithHeaders performs an HTTP GET request with custom headers.
func (*Client) HeadWithHeaders ¶
func (c *Client) HeadWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)
HeadWithHeaders performs an HTTP HEAD request with custom headers.
func (*Client) PostForm ¶
func (c *Client) PostForm(ctx context.Context, requestURL string, values url.Values) (*Response, error)
PostForm performs an HTTP POST request with form-encoded body.
func (*Client) PostFormWithHeaders ¶
func (c *Client) PostFormWithHeaders(ctx context.Context, requestURL string, values url.Values, headers map[string]string) (*Response, error)
PostFormWithHeaders performs an HTTP POST request with form-encoded body and custom headers.
func (*Client) PostJSON ¶
PostJSON performs a POST request with a JSON body and unmarshals the response into dest.
type Option ¶
type Option func(*Options)
Option is a functional option for configuring the HTTP client.
func WithBlockCrossDomainRedirects ¶
func WithBlockCrossDomainRedirects() Option
WithBlockCrossDomainRedirects blocks redirects that change the host.
func WithDefaultHeaders ¶
WithDefaultHeaders sets headers that are applied to every request.
func WithHTTPProxy ¶ added in v0.1.0
WithHTTPProxy sets an HTTP/HTTPS proxy URL for all requests. The proxyURL should be in the format: http://[user:pass@]host:port
func WithMaxRedirects ¶
WithMaxRedirects sets the maximum number of redirects to follow. Set to 0 to disable redirects. Default is 10.
func WithMaxResponseBodyBytes ¶ added in v0.2.0
WithMaxResponseBodyBytes limits buffered response bodies. Non-positive values retain the default unlimited buffering. Oversized responses return the bounded body and ErrResponseBodyTooLarge.
func WithRedirectTracking ¶
func WithRedirectTracking() Option
WithRedirectTracking enables tracking of the full redirect chain in responses.
func WithSOCKSProxy ¶ added in v0.1.0
WithSOCKSProxy sets a SOCKS5 proxy URL for all requests. The proxyURL should be in the format: socks5://[user:pass@]host:port
func WithTLSVerify ¶
WithTLSVerify controls certificate verification for the default transport. WithTransport takes precedence over this option.
func WithTimeout ¶
WithTimeout sets the HTTP request timeout.
func WithTransport ¶ added in v0.2.0
WithTransport supplies a transport to clone for this client's exclusive use. Its dialing, TLS, HTTP/2, and connection settings replace the defaults, including WithTLSVerify. Explicit proxy options still apply; SOCKS replaces DialContext. A nil transport selects the default transport. Do not mutate the supplied transport's configuration while New is cloning it.
type Options ¶
type Options struct {
Timeout time.Duration
VerifyTLS bool
MaxRedirects int
TrackRedirects bool
BlockCrossDomainRedirects bool
DefaultHeaders map[string]string
HTTPProxy string
SOCKSProxy string
Transport *http.Transport
MaxResponseBodyBytes int64
}
Options configures the HTTP client behavior.
type RedirectHop ¶
RedirectHop records a single redirect in the chain.