httpx

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httpx provides WaxSeal's Google-facing HTTP behavior. It wraps a caller's HTTP client with bounded retries, jittered backoff, Retry-After handling, and response size limits.

No pause outlasts the caller's deadline. A backoff that would consume the remaining budget is skipped and the failure that provoked it is returned instead, so the cause reaches the caller rather than a bare context timeout that names nothing. MaxDelay is the absolute cap on a pause; this is the per-request one.

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyTooLarge = errors.New("httpx: response body exceeds cap")

ErrBodyTooLarge is returned when a response body exceeds the configured limit.

Functions

func ReadBodyCapped

func ReadBodyCapped(r io.Reader, maxBody int64) ([]byte, error)

ReadBodyCapped reads up to maxBody bytes, returning ErrBodyTooLarge if the source has more (no silent truncation).

Types

type Client

type Client struct {
	HTTP       *http.Client
	MaxRetries int           // retries AFTER the first attempt (default 2)
	BaseDelay  time.Duration // backoff base (default 500ms)
	MaxDelay   time.Duration // backoff cap (default 5s)
	Logger     *slog.Logger
}

Client wraps an *http.Client with bounded, jittered retries and Retry-After handling. Construct one with New.

func New

func New(hc *http.Client) *Client

New wraps hc with default retry and backoff settings. A nil hc uses http.DefaultClient. There is no client-level Timeout (it interacts poorly with multi-attempt retries); callers must drive each request with a bounded context.

func (*Client) DoJSON

func (c *Client) DoJSON(req *http.Request, maxBody int64) ([]byte, error)

DoJSON runs req, requires a 2xx status, and returns a body no larger than maxBody.

DoJSON reads the body inside the retry loop, so it retries connections that fail after headers arrive. ErrBodyTooLarge is never retried.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL