Documentation
¶
Overview ¶
Package httpx provides the HTTP transport shared by every client in the CLI. It sends the CLI user agent, maps HTTP statuses onto typed application errors, retries safe reads with backoff, and writes one redacted debug record per attempt.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RedactBody ¶
RedactBody returns a log-safe rendering of a request or response body. JSON bodies keep their structure with sensitive values replaced; form bodies are re-encoded the same way. Anything else is reduced to "<N bytes>".
func RedactHeader ¶
RedactHeader returns the header values as a map with every sensitive header replaced by "REDACTED". Values of non-sensitive headers with several entries are joined with ", ".
Types ¶
type Client ¶
type Client struct {
// HTTP is the underlying client. Do falls back to http.DefaultClient when
// it is nil.
HTTP *http.Client
// UserAgent is sent on every request.
UserAgent string
// Logger receives one debug record per attempt. A nil Logger disables
// debug logging.
Logger *slog.Logger
// Attempts is the maximum number of attempts one Do call makes.
Attempts int
// Backoff returns how long to wait before retry attempt n (1 for the
// first wait). A nil Backoff means no wait.
Backoff func(attempt int) time.Duration
}
Client is the shared HTTP transport. It is safe for concurrent use.
type Request ¶
type Request struct {
// Method is the HTTP method. An empty Method means GET.
Method string
// URL is the full request URL, query string included.
URL string
// Header holds extra request headers. It is cloned, never mutated.
Header http.Header
// Body is the request body, sent as-is.
Body []byte
// Retry allows retries on retryable failures. Only safe reads should set
// it.
Retry bool
// Endpoint is the API path reported in errors and logs. It defaults to
// the path of URL.
Endpoint string
}
Request is one HTTP call. Endpoint defaults to the URL path and is the only location that appears in errors.