chttp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package chttp provides the HTTP client every katbyte tool talks to APIs with: trace-level request/response logging through clog, per-attempt timeouts so a stalled server fails fast, and retries for transient failures that are careful never to re-send a mutation whose outcome is unknown.

Index

Constants

View Source
const DefaultMaxRetry = 3

DefaultMaxRetry is how many attempts NewHTTPClient makes before giving up: enough to ride through a blip or a single rate-limit window without turning an outage into a minutes-long hang.

View Source
const MaxRetryAfter = 60 * time.Second

MaxRetryAfter caps how long a Retry-After header can make a retry wait. A server asking for more than this is telling an interactive tool to come back later, not to sit there.

Variables

This section is empty.

Functions

func MarkRetrySafe

func MarkRetrySafe(req *http.Request) *http.Request

MarkRetrySafe declares a request safe to re-send even though its method is not idempotent: a GraphQL or JQL query is a read that happens to travel as a POST. Reads with idempotent methods (GET, HEAD, OPTIONS) need no mark.

func NewBaseTransport

func NewBaseTransport() http.RoundTripper

NewBaseTransport returns http.DefaultTransport tuned with per-attempt timeouts so a stalled connection or unresponsive server fails fast and gets retried by RetryTransport instead of hanging the command. It is exported so callers that must build their own client (oauth2, for one) can still start from the same transport.

func NewHTTPClient

func NewHTTPClient(name string) *http.Client

NewHTTPClient returns a client that trace-logs every exchange under name and retries transient failures up to DefaultMaxRetry times. name appears in the logs so a tool talking to two APIs can tell their traffic apart.

Types

type RetryTransport

type RetryTransport struct {
	// contains filtered or unexported fields
}

RetryTransport wraps an http.RoundTripper with retry logic for transient failures: 429 (rate limited) for every request, plus connection errors and 5xx (server error) responses for retry-safe requests only (see MarkRetrySafe). Attempts back off exponentially (1s, 2s, 4s, ...), a 429's Retry-After header is honoured up to MaxRetryAfter, and a cancelled request context aborts the wait.

func NewRetryTransport

func NewRetryTransport(name string, next http.RoundTripper, maxRetry int) *RetryTransport

NewRetryTransport wraps next with up to maxRetry attempts under name. A maxRetry below 1 is treated as 1: every request is sent at least once.

func (*RetryTransport) RoundTrip

func (t *RetryTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport is an http.RoundTripper that dumps each request and response to clog.Log at TRACE, with JSON bodies pretty-printed. The dumps include headers, so they are only produced when TRACE is actually enabled.

func NewTransport

func NewTransport(name string, next http.RoundTripper) *Transport

NewTransport wraps next with trace logging under name.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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