httpclient

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package httpclient provides authentication-aware HTTP transports for upstream requests.

Index

Constants

View Source
const DefaultHoldRefresh = 2 * time.Second

DefaultHoldRefresh is how long a SharedRateLimitGate trusts its copy of the shared holds before reading them again. It bounds both the database reads, at one per interval per instance, and how long another instance may keep sending after a hold is placed.

Variables

This section is empty.

Functions

func NewAccessLogTransport added in v0.8.0

func NewAccessLogTransport(base http.RoundTripper, log *accesslog.Logger, logger *slog.Logger) http.RoundTripper

NewAccessLogTransport records each upstream HTTP exchange around base.

Types

type AuthFunc

type AuthFunc func(url string) (headerName, headerValue string)

AuthFunc returns a configured authentication header for a URL.

type HoldStore added in v0.11.0

type HoldStore interface {
	PutUpstreamHold(host string, until time.Time) error
	UpstreamHolds(now time.Time) (map[string]time.Time, error)
}

HoldStore keeps rate-limit holds where every instance sharing it sees them.

type SharedRateLimitGate added in v0.11.0

type SharedRateLimitGate struct {

	// Refresh is how long the shared holds read from the store are used
	// before reading them again. Set it before use.
	Refresh time.Duration
	// contains filtered or unexported fields
}

SharedRateLimitGate adds holds shared with other instances to a RateLimitGate. Holds the gate places are published to the store, and requests to a host another instance holds are refused like the gate's own, with a HeldError. Without a store it behaves as the gate alone.

func NewSharedRateLimitGate added in v0.11.0

func NewSharedRateLimitGate(gate *registryclient.RateLimitGate, store HoldStore, logger *slog.Logger) *SharedRateLimitGate

NewSharedRateLimitGate wraps gate, publishing its holds to store and honouring those in store. It takes over gate.OnHold, calling the callback set before. A nil store shares nothing.

func (*SharedRateLimitGate) Held added in v0.11.0

func (s *SharedRateLimitGate) Held(rawURL string) error

Held returns a *registryclient.HeldError when requests to rawURL's host are held by this instance or another, and nil otherwise. It is safe to call on a nil gate.

func (*SharedRateLimitGate) Holds added in v0.11.0

func (s *SharedRateLimitGate) Holds() map[string]time.Time

Holds returns the hosts held by this instance or another, and when each hold ends. It is safe to call on a nil gate.

func (*SharedRateLimitGate) Reload added in v0.11.0

func (s *SharedRateLimitGate) Reload()

Reload reads the shared holds now rather than when the copy runs out. A caller that knows another instance has just failed, say on a 429, uses it to see that instance's hold at once.

func (*SharedRateLimitGate) RoundTrip added in v0.11.0

func (s *SharedRateLimitGate) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type Transport

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

Transport adds configured authentication and follows OCI Bearer challenges.

func NewTransport

func NewTransport(base http.RoundTripper, authForURL AuthFunc) *Transport

NewTransport creates an authentication-aware transport around base.

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