middleware

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigurationKeyRequestAttempts = "internal_network_request_max_attempts"
View Source
const ConfigurationKeyRetryAfter = "internal_network_request_retry_after_seconds"

Variables

View Source
var ErrAuthenticationFailed = fmt.Errorf("authentication failed")

ErrAuthenticationFailed indicates that authentication failed in the networking middleware.

Functions

func AddAuthenticationHeader

func AddAuthenticationHeader(
	authenticator auth.Authenticator,
	config configuration.Configuration,
	request *http.Request,
) error

AddAuthenticationHeader determines whether a request needs authentication, negotiates authorization and sets request headers if necessary.

If this fails due to an authentication error, the resulting error will match ErrAuthenticationFailed.

func ApplyTlsConfig

func ApplyTlsConfig(transport *http.Transport, insecure bool, caPool *x509.CertPool) *http.Transport

func ConfigureProxy

func ConfigureProxy(
	transport *http.Transport,
	logger *zerolog.Logger,
	proxy func(req *http.Request) (*url.URL, error),
	authenticationMechanism httpauth.AuthenticationMechanism,
) *http.Transport

func HandleResponse

func HandleResponse(res *http.Response, config configuration.Configuration) error

HandleResponse maps the response param to the error catalog error.

func ShouldRequireAuthentication

func ShouldRequireAuthentication(
	apiUrl string,
	url *url.URL,
	additionalSubdomains []string,
	additionalUrls []string,
) (matchesPattern bool, err error)

Types

type AuthHeaderMiddleware

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

func NewAuthHeaderMiddleware

func NewAuthHeaderMiddleware(
	config configuration.Configuration,
	authenticator auth.Authenticator,
	roundTripper http.RoundTripper,
) *AuthHeaderMiddleware

func NewAuthHeaderMiddlewareWithLogger added in v0.3.0

func NewAuthHeaderMiddlewareWithLogger(
	config configuration.Configuration,
	authenticator auth.Authenticator,
	roundTripper http.RoundTripper,
	logger *zerolog.Logger,
) *AuthHeaderMiddleware

func (*AuthHeaderMiddleware) RoundTrip

func (n *AuthHeaderMiddleware) RoundTrip(request *http.Request) (*http.Response, error)

type NetworkStackErrorHandlerMiddleware

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

NetworkStackErrorHandlerMiddleware is a middleware that handles network errors that are not yet error catalog errors.

func NewNetworkStackErrorHandlerMiddleware

func NewNetworkStackErrorHandlerMiddleware(roundTriper http.RoundTripper, errHandler networktypes.ErrorHandlerFunc) *NetworkStackErrorHandlerMiddleware

func (*NetworkStackErrorHandlerMiddleware) RoundTrip

type ResponseMiddleware

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

func NewReponseMiddleware

func NewReponseMiddleware(roundTriper http.RoundTripper, config configuration.Configuration, errHandler networktypes.ErrorHandlerFunc) *ResponseMiddleware

func (ResponseMiddleware) RoundTrip

func (rm ResponseMiddleware) RoundTrip(req *http.Request) (*http.Response, error)

type RetryAttemptError added in v0.2.0

type RetryAttemptError struct {
	StatusCode  int
	Attempt     int
	MaxAttempts int
	Duration    time.Duration
	Err         error
}

func (*RetryAttemptError) Error added in v0.2.0

func (e *RetryAttemptError) Error() string

func (*RetryAttemptError) Unwrap added in v0.2.0

func (e *RetryAttemptError) Unwrap() error

type RetryMiddleware

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

func NewRetryMiddleware

func NewRetryMiddleware(config configuration.Configuration, logger *zerolog.Logger, roundTripper http.RoundTripper, opts ...RetryMiddlewareOption) *RetryMiddleware

func (RetryMiddleware) RoundTrip

func (rm RetryMiddleware) RoundTrip(req *http.Request) (*http.Response, error)

type RetryMiddlewareOption added in v0.2.0

type RetryMiddlewareOption func(*RetryMiddleware)

func WithErrorHandler added in v0.2.0

func WithErrorHandler(handler networktypes.ErrorHandlerFunc) RetryMiddlewareOption

func WithRetryInterval added in v0.18.0

func WithRetryInterval(interval time.Duration) RetryMiddlewareOption

WithRetryInterval sets the initial backoff between attempts for this middleware instance, overriding the configured value. Use it for callers on a tighter time budget than a user-facing API request, such as work done during teardown. Server-suggested Retry-After delays are not affected by this override.

Jump to

Keyboard shortcuts

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