Documentation
¶
Overview ¶
Package proxy holds the forwarding, admission, and serving code shared by proxies.
Index ¶
- func NewReverseProxy(target *netaddr.Endpoint, transport http.RoundTripper, log *slog.Logger, ...) (*httputil.ReverseProxy, error)
- func Serve(ctx context.Context, config Config, log *slog.Logger, bindings []Binding, ...) error
- type Binding
- type Budget
- type CandidateRun
- type Candidates
- type Config
- type Lifecycle
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewReverseProxy ¶
func NewReverseProxy(target *netaddr.Endpoint, transport http.RoundTripper, log *slog.Logger, discard bool) (*httputil.ReverseProxy, error)
NewReverseProxy forwards requests to a backend target with trusted forwarding headers. A discarding proxy logs failures as candidate failures and writes no response.
Types ¶
type Binding ¶
type Binding struct {
// contains filtered or unexported fields
}
Binding pairs a listener with the handler that serves its connections.
type Budget ¶
type Budget struct {
// contains filtered or unexported fields
}
Budget caps buffered memory shared across every in-flight request. Reservations never block, so a full budget fails immediately.
type CandidateRun ¶
type CandidateRun struct {
// contains filtered or unexported fields
}
CandidateRun is one admitted unit of candidate work. Its pointer gives the non-comparable cancellation function a stable map identity.
type Candidates ¶
type Candidates struct {
// contains filtered or unexported fields
}
Candidates admits candidate work and tracks it so quarantine and shutdown can cancel everything in flight. Quarantine lasts for the process lifetime.
func NewCandidates ¶
func NewCandidates(maxInFlight int, log *slog.Logger) *Candidates
NewCandidates tracks candidate work, quarantining beyond maxInFlight concurrent runs.
func (*Candidates) Close ¶ added in v0.15.0
func (c *Candidates) Close()
Close refuses further candidate work and cancels active runs without waiting.
func (*Candidates) Finish ¶
func (c *Candidates) Finish(run *CandidateRun)
Finish releases an admitted run once all of its work has stopped.
func (*Candidates) Quarantine ¶
func (c *Candidates) Quarantine(ctx context.Context, reason error)
Quarantine refuses all further candidate work and cancels active runs.
func (*Candidates) Shutdown ¶
func (c *Candidates) Shutdown(ctx context.Context) error
Shutdown refuses further candidate work and waits for active runs to finish.
func (*Candidates) Start ¶
func (c *Candidates) Start(ctx context.Context, cancel context.CancelFunc) Option[*CandidateRun]
Start admits candidate work that cancel stops, returning None when it is refused. Exceeding the concurrency limit quarantines the candidate.
type Config ¶
type Config struct {
// MaxInFlightRequests limits concurrent proxied requests.
MaxInFlightRequests int `default:"256" help:"Maximum concurrent proxied requests."`
// MaxConnections limits concurrent client connections.
MaxConnections int `default:"512" help:"Maximum concurrent client connections."`
// ReadHeaderTimeout limits the duration spent reading request headers.
ReadHeaderTimeout time.Duration `default:"10s" help:"Maximum duration for reading request headers."`
// IdleTimeout limits how long an idle client connection remains open.
IdleTimeout time.Duration `default:"1m" help:"Maximum idle client connection duration."`
// MaxHeaderBytes limits the size of request and response headers.
MaxHeaderBytes int `default:"65536" help:"Maximum request header size in bytes."`
// ShutdownTimeout limits graceful server shutdown.
ShutdownTimeout time.Duration `default:"10s" help:"Maximum graceful shutdown duration."`
}
Config contains the server and forwarding limits shared by every proxy.
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle holds the proxy-specific steps that Serve runs around its servers.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport forwards HTTP/1, encrypted HTTP/2, and unencrypted HTTP/2 requests.
func NewTransport ¶
NewTransport constructs transports for HTTP/1, encrypted HTTP/2, and h2c.
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections closes idle connections held by every underlying transport.
func (*Transport) ForBackend ¶
func (t *Transport) ForBackend(target *netaddr.Endpoint) http.RoundTripper
ForBackend selects the transport for a backend, dialing its unix socket when the backend uses one.