http_client

package
v0.0.0-...-40ae8b9 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LabelClient = types.LabelClient
	LabelHost   = types.LabelHost
	LabelMethod = types.LabelMethod
	LabelSource = types.LabelSource
)

Label constants for backward compatibility.

Variables

This section is empty.

Functions

func Chain

func Chain(mw ...types.Middleware) types.Middleware

Chain builds a middleware pipeline.

func New

func New(opts ...Option) (*http.Client, error)

New constructs an HTTP client with optional rate limiting, hedging, and middleware.

func NewTokenBucketLimiter

func NewTokenBucketLimiter(ratePerSec float64, burst int, jitterFraction float64) (*tokenBucketLimiter, error)

Types

type Limiter

type Limiter = types.Limiter

Limiter is an alias for types.Limiter for backward compatibility.

type Metrics

type Metrics = types.Metrics

Metrics is an alias for types.Metrics for backward compatibility.

func NewMetrics

func NewMetrics(namespace, subsystem string) *Metrics

NewMetrics creates a new Metrics instance.

type Middleware

type Middleware = types.Middleware

Middleware is an alias for types.Middleware for backward compatibility.

type Option

type Option func(*config) error

Option configures an HTTP client during construction.

func WithBaseTransport

func WithBaseTransport(rt http.RoundTripper) Option

WithBaseTransport sets the base HTTP transport to wrap with middleware. If nil, http.DefaultTransport is used.

func WithClientName

func WithClientName(name string) Option

WithClientName sets the client name used for metrics and tracing.

func WithDeadlineThreshold

func WithDeadlineThreshold(t time.Duration) Option

WithDeadlineThreshold sets the minimum time before a context deadline at which requests will be rejected early. If a request's deadline is closer than this threshold, it will be canceled immediately.

func WithHedge

func WithHedge(opts ...hedge.Option) Option

WithHedge enables adaptive hedged requests on the stack below OpenTelemetry (otelhttp remains the outer RoundTripper so each logical Do keeps one trace span). See https://github.com/bhope/hedge

func WithJitter

func WithJitter(fraction float64) Option

WithJitter sets the jitter fraction for the token bucket limiter. Fraction should be between 0 and 1. Negative values are normalized to 0, values greater than 1 are normalized to 1.

func WithMetrics

func WithMetrics(m *Metrics) Option

WithMetrics sets the Prometheus metrics collector.

func WithRateLimit

func WithRateLimit(rate float64, burst int) Option

WithRateLimit configures the local token bucket rate limiter. Rate is in requests per second, burst is the maximum number of tokens. Both must be positive for the limiter to be created.

func WithServerHeaderJitter

func WithServerHeaderJitter(fraction float64) Option

WithServerHeaderJitter sets the jitter fraction for server rate limit waits. Fraction should be between 0 and 1. Negative values are normalized to 0, values greater than 1 are normalized to 1.

type RoundTripperFunc

type RoundTripperFunc = types.RoundTripperFunc

RoundTripperFunc is an alias for types.RoundTripperFunc for backward compatibility.

Directories

Path Synopsis
internal
middleware
serverlimit
Package serverlimit provides HTTP client middleware for respecting server-specified rate limits via Retry-After and RateLimit-Reset headers.
Package serverlimit provides HTTP client middleware for respecting server-specified rate limits via Retry-After and RateLimit-Reset headers.

Jump to

Keyboard shortcuts

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