middleware

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationHeader      = "Authorization"
	ProxyAuthorizationHeader = "Proxy-Authorization"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

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

BasicAuth exposes common Basic Authentication functionalities from the standard library, and allows to customize the Authentication header. This is useful when you want to use Basic Authentication for a proxy.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization

func NewBasicAuth

func NewBasicAuth() *BasicAuth

func NewProxyBasicAuth

func NewProxyBasicAuth() *BasicAuth

func (*BasicAuth) AuthenticatedRequest

func (ba *BasicAuth) AuthenticatedRequest(r *http.Request, expectedUser, expectedPass string) bool

AuthenticatedRequest parses the provided HTTP request for Basic Authentication credentials and returns true if the provided credentials match the expected username and password. Returns false if the request is unauthenticated. Uses constant-time comparison in order to mitigate timing attacks.

func (*BasicAuth) BasicAuth

func (ba *BasicAuth) BasicAuth(r *http.Request) (username, password string, ok bool)

BasicAuth returns the username and password provided in the request's authorization header, if the request uses HTTP Basic Authentication. See RFC 2617, Section 2.

func (*BasicAuth) Wrap

func (ba *BasicAuth) Wrap(h http.Handler, expectedUser, expectedPass string) http.Handler

Wrap wraps the provided http.Handler with basic authentication. If header is Proxy-Authorization and the request is not authenticated, the handler is not called and a 407 Proxy Authentication Required is returned. Otherwise, if the request is not authenticated, the handler is not called and a 401 Unauthorized is returned. The provided username and password are used to authenticate the request.

type LogEntry

type LogEntry struct {
	Request  *http.Request
	Response *http.Response
	Status   int
	Duration time.Duration
}

type Logger

type Logger func(e LogEntry)

func (Logger) ModifyResponse

func (l Logger) ModifyResponse(res *http.Response) error

func (Logger) Wrap

func (l Logger) Wrap(h http.Handler) http.Handler

func (Logger) WrapRoundTripper added in v1.1.1

func (l Logger) WrapRoundTripper(rt http.RoundTripper) http.RoundTripper

type Prometheus

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

Prometheus is a middleware that collects metrics about the HTTP requests and responses. Unlike the promhttp.InstrumentHandler* chaining, this middleware creates only one delegator per request. It partitions the metrics by HTTP status code, HTTP method, destination host name and source IP.

func NewPrometheus

func NewPrometheus(r prometheus.Registerer, namespace string) *Prometheus

func (*Prometheus) ModifyRequest

func (p *Prometheus) ModifyRequest(req *http.Request) error

func (*Prometheus) ModifyResponse

func (p *Prometheus) ModifyResponse(res *http.Response) error

func (*Prometheus) ReadRequest added in v1.2.0

func (p *Prometheus) ReadRequest(req *http.Request)

func (*Prometheus) Wrap

func (p *Prometheus) Wrap(h http.Handler) http.Handler

func (*Prometheus) WroteResponse added in v1.2.0

func (p *Prometheus) WroteResponse(res *http.Response)

Jump to

Keyboard shortcuts

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