Documentation
¶
Overview ¶
Package httpx provides HTTP plumbing shared by provider API clients: a redacting debug-logging transport, a conservative retry transport that understands HTTP 429 / Retry-After, Link header parsing and small helpers.
It deliberately contains no provider-specific behavior. Each driver owns its API client (base URL, auth headers, pagination, error mapping) and only borrows these building blocks.
Index ¶
- func DecodeJSON(resp *http.Response, v any) error
- func NewClient(o Options) *http.Client
- func ParseLinkHeader(h string) map[string]string
- func ReadBody(resp *http.Response, limit int64) []byte
- func RetryAfter(h http.Header) time.Duration
- func Sleep(ctx context.Context, d time.Duration) error
- func UserAgent() string
- func WithNoRetry(ctx context.Context) context.Context
- func WithRetrySafe(ctx context.Context) context.Context
- type LoggingTransport
- type Options
- type RetryPolicy
- type RetryTransport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes a JSON response body into v.
func ParseLinkHeader ¶
ParseLinkHeader parses an RFC 8288 Link header into rel -> URL.
func RetryAfter ¶
RetryAfter parses a Retry-After header (delta-seconds or HTTP date).
func WithNoRetry ¶
WithNoRetry disables retries for a request.
Types ¶
type LoggingTransport ¶
type LoggingTransport struct {
Base http.RoundTripper
Logger *slog.Logger
}
LoggingTransport logs requests at debug level with credentials redacted.
type Options ¶
type Options struct {
Timeout time.Duration
Logger *slog.Logger
Retry RetryPolicy
// Base is the underlying transport (defaults to http.DefaultTransport).
Base http.RoundTripper
}
Options configure NewClient.
type RetryPolicy ¶
type RetryPolicy struct {
MaxRetries int
BaseDelay time.Duration
MaxDelay time.Duration
// MaxWait is the longest Retry-After we are willing to sleep for. Longer
// waits surface as rate-limit errors to the caller instead.
MaxWait time.Duration
// RateLimited lets a driver recognize provider-specific rate limit
// responses (e.g. GitHub's 403 + x-ratelimit-remaining: 0) and return the
// wait duration if known.
RateLimited func(resp *http.Response) (limited bool, wait time.Duration)
// Disabled turns off retries entirely.
Disabled bool
}
RetryPolicy controls RetryTransport.
type RetryTransport ¶
type RetryTransport struct {
Base http.RoundTripper
Policy RetryPolicy
Logger *slog.Logger
}
RetryTransport retries idempotent requests on 429, transient 5xx and network errors with exponential backoff and jitter, honoring Retry-After and context cancellation. Non-idempotent requests (POST, PATCH, DELETE...) are never retried unless marked with WithRetrySafe.