Back to godoc.org

Package middlewares

v1.7.14
Latest Go to latest

The highest tagged major version is .

Published: Aug 14, 2019 | License: MIT | Module: git.lug.ustc.edu.cn/github.com/containous/traefik

Index

Constants

const (
	// ReplacePathKey is the key within the request context used to
	// store the replaced path
	ReplacePathKey key = "ReplacePath"
	// ReplacedPathHeader is the default header to set the old path to
	ReplacedPathHeader = "X-Replaced-Path"
)
const (
	// StripPrefixKey is the key within the request context used to
	// store the stripped prefix
	StripPrefixKey key = "StripPrefix"
	// ForwardedPrefixHeader is the default header to set prefix
	ForwardedPrefixHeader = "X-Forwarded-Prefix"
)
const (
	// AddPrefixKey is the key within the request context used to
	// store the added prefix
	AddPrefixKey key = "AddPrefix"
)

func GetCanonizedHost

func GetCanonizedHost(ctx context.Context) string

GetCanonizedHost plucks the canonized host key from the request of a context that was put through the middleware

func NegroniRecoverHandler

func NegroniRecoverHandler() negroni.Handler

NegroniRecoverHandler recovers from a panic in negroni handlers

func NewBackendMetricsMiddleware

func NewBackendMetricsMiddleware(registry metrics.Registry, backendName string) negroni.Handler

NewBackendMetricsMiddleware creates a new metrics middleware for a Backend.

func NewCircuitBreakerOptions

func NewCircuitBreakerOptions(expression string) cbreaker.CircuitBreakerOption

NewCircuitBreakerOptions returns a new CircuitBreakerOption

func NewEntryPointMetricsMiddleware

func NewEntryPointMetricsMiddleware(registry metrics.Registry, entryPointName string) negroni.Handler

NewEntryPointMetricsMiddleware creates a new metrics middleware for an Entrypoint.

func NewReplacePathRegexHandler

func NewReplacePathRegexHandler(regex string, replacement string, handler http.Handler) http.Handler

NewReplacePathRegexHandler returns a new ReplacePathRegex

func NewSecure

func NewSecure(headers *types.Headers) *secure.Secure

NewSecure constructs a new Secure instance with supplied options.

func RecoverHandler

func RecoverHandler(next http.Handler) http.Handler

RecoverHandler recovers from a panic in http handlers

type AddPrefix

type AddPrefix struct {
	Handler http.Handler
	Prefix  string
}

AddPrefix is a middleware used to add prefix to an URL request

func (*AddPrefix) ServeHTTP

func (s *AddPrefix) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*AddPrefix) SetHandler

func (s *AddPrefix) SetHandler(Handler http.Handler)

SetHandler sets handler

type CircuitBreaker

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

CircuitBreaker holds the oxy circuit breaker.

func NewCircuitBreaker

func NewCircuitBreaker(next http.Handler, expression string, options ...cbreaker.CircuitBreakerOption) (*CircuitBreaker, error)

NewCircuitBreaker returns a new CircuitBreaker.

func (*CircuitBreaker) ServeHTTP

func (cb *CircuitBreaker) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type Compress

type Compress struct{}

Compress is a middleware that allows redirection

func (*Compress) ServeHTTP

func (c *Compress) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServeHTTP is a function used by Negroni

type DistinguishedNameOptions

type DistinguishedNameOptions struct {
	CommonName          bool
	CountryName         bool
	DomainComponent     bool
	LocalityName        bool
	OrganizationName    bool
	SerialNumber        bool
	StateOrProvinceName bool
}

DistinguishedNameOptions is a struct for specifying the configuration for the distinguished name info.

type EmptyBackendHandler

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

EmptyBackendHandler is a middlware that checks whether the current Backend has at least one active Server in respect to the healthchecks and if this is not the case, it will stop the middleware chain and respond with 503.

func NewEmptyBackendHandler

func NewEmptyBackendHandler(lb healthcheck.BalancerHandler) *EmptyBackendHandler

NewEmptyBackendHandler creates a new EmptyBackendHandler instance.

func (*EmptyBackendHandler) ServeHTTP

func (h *EmptyBackendHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP responds with 503 when there is no active Server and otherwise invokes the next handler in the middleware chain.

type HandlerSwitcher

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

HandlerSwitcher allows hot switching of http.ServeMux

func NewHandlerSwitcher

func NewHandlerSwitcher(newHandler *mux.Router) (hs *HandlerSwitcher)

NewHandlerSwitcher builds a new instance of HandlerSwitcher

func (*HandlerSwitcher) GetHandler

func (hs *HandlerSwitcher) GetHandler() (newHandler *mux.Router)

GetHandler returns the current http.ServeMux

func (*HandlerSwitcher) ServeHTTP

func (hs *HandlerSwitcher) ServeHTTP(rw http.ResponseWriter, r *http.Request)

func (*HandlerSwitcher) UpdateHandler

func (hs *HandlerSwitcher) UpdateHandler(newHandler *mux.Router)

UpdateHandler safely updates the current http.ServeMux with a new one

type HeaderOptions

type HeaderOptions struct {
	// If Custom request headers are set, these will be added to the request
	CustomRequestHeaders map[string]string
	// If Custom response headers are set, these will be added to the ResponseWriter
	CustomResponseHeaders map[string]string
}

HeaderOptions is a struct for specifying configuration options for the headers middleware.

type HeaderStruct

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

HeaderStruct is a middleware that helps setup a few basic security features. A single headerOptions struct can be provided to configure which features should be enabled, and the ability to override a few of the default values.

func NewHeaderFromStruct

func NewHeaderFromStruct(headers *types.Headers) *HeaderStruct

NewHeaderFromStruct constructs a new header instance from supplied frontend header struct.

func (*HeaderStruct) ModifyRequestHeaders

func (s *HeaderStruct) ModifyRequestHeaders(r *http.Request)

ModifyRequestHeaders set or delete request headers

func (*HeaderStruct) ModifyResponseHeaders

func (s *HeaderStruct) ModifyResponseHeaders(res *http.Response) error

ModifyResponseHeaders set or delete response headers

func (*HeaderStruct) ServeHTTP

func (s *HeaderStruct) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type IPWhiteLister

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

IPWhiteLister is a middleware that provides Checks of the Requesting IP against a set of Whitelists

func NewIPWhiteLister

func NewIPWhiteLister(whiteList []string, useXForwardedFor bool) (*IPWhiteLister, error)

NewIPWhiteLister builds a new IPWhiteLister given a list of CIDR-Strings to whitelist

func (*IPWhiteLister) ServeHTTP

func (wl *IPWhiteLister) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type MetricsRetryListener

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

MetricsRetryListener is an implementation of the RetryListener interface to record RequestMetrics about retry attempts.

func (*MetricsRetryListener) Retried

func (m *MetricsRetryListener) Retried(req *http.Request, attempt int)

Retried tracks the retry in the RequestMetrics implementation.

type ReplacePath

type ReplacePath struct {
	Handler http.Handler
	Path    string
}

ReplacePath is a middleware used to replace the path of a URL request

func (*ReplacePath) ServeHTTP

func (s *ReplacePath) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ReplacePathRegex

type ReplacePathRegex struct {
	Handler     http.Handler
	Regexp      *regexp.Regexp
	Replacement string
}

ReplacePathRegex is a middleware used to replace the path of a URL request with a regular expression

func (*ReplacePathRegex) ServeHTTP

func (s *ReplacePathRegex) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RequestHost

type RequestHost struct{}

RequestHost is the struct for the middleware that adds the CanonicalDomain of the request Host into a context for later use.

func (*RequestHost) ServeHTTP

func (rh *RequestHost) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type Retry

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

Retry is a middleware that retries requests

func NewRetry

func NewRetry(attempts int, next http.Handler, listener RetryListener) *Retry

NewRetry returns a new Retry instance

func (*Retry) ServeHTTP

func (retry *Retry) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type RetryListener

type RetryListener interface {
	// Retried will be called when a retry happens, with the request attempt passed to it.
	// For the first retry this will be attempt 2.
	Retried(req *http.Request, attempt int)
}

RetryListener is used to inform about retry attempts.

func NewMetricsRetryListener

func NewMetricsRetryListener(retryMetrics retryMetrics, backendName string) RetryListener

NewMetricsRetryListener instantiates a MetricsRetryListener with the given retryMetrics.

type RetryListeners

type RetryListeners []RetryListener

RetryListeners is a convenience type to construct a list of RetryListener and notify each of them about a retry attempt.

func (RetryListeners) Retried

func (l RetryListeners) Retried(req *http.Request, attempt int)

Retried exists to implement the RetryListener interface. It calls Retried on each of its slice entries.

type Routes

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

Routes holds the gorilla mux routes (for the API & co).

func NewRoutes

func NewRoutes(router *mux.Router) *Routes

NewRoutes return a Routes based on the given router.

func (*Routes) ServeHTTP

func (router *Routes) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type Stateful

type Stateful interface {
	http.ResponseWriter
	http.Hijacker
	http.Flusher
	http.CloseNotifier
}

Stateful interface groups all http interfaces that must be implemented by a stateful middleware (ie: recorders)

type Stats

type Stats struct {
	RecentErrors []*statsError `json:"recent_errors"`
}

Stats includes all of the stats gathered by the recorder.

type StatsRecorder

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

StatsRecorder is an optional middleware that records more details statistics about requests and how they are processed. This currently consists of recent requests that have caused errors (4xx and 5xx status codes), making it easy to pinpoint problems.

func NewStatsRecorder

func NewStatsRecorder(numRecentErrors int) *StatsRecorder

NewStatsRecorder returns a new StatsRecorder

func (*StatsRecorder) Data

func (s *StatsRecorder) Data() *Stats

Data returns a copy of the statistics that have been gathered.

func (*StatsRecorder) ServeHTTP

func (s *StatsRecorder) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServeHTTP silently extracts information from the request and response as it is processed. If the response is 4xx or 5xx, add it to the list of 10 most recent errors.

type StripPrefix

type StripPrefix struct {
	Handler  http.Handler
	Prefixes []string
}

StripPrefix is a middleware used to strip prefix from an URL request

func (*StripPrefix) ServeHTTP

func (s *StripPrefix) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*StripPrefix) SetHandler

func (s *StripPrefix) SetHandler(Handler http.Handler)

SetHandler sets handler

type StripPrefixRegex

type StripPrefixRegex struct {
	Handler http.Handler
	// contains filtered or unexported fields
}

StripPrefixRegex is a middleware used to strip prefix from an URL request

func NewStripPrefixRegex

func NewStripPrefixRegex(handler http.Handler, prefixes []string) *StripPrefixRegex

NewStripPrefixRegex builds a new StripPrefixRegex given a handler and prefixes

func (*StripPrefixRegex) ServeHTTP

func (s *StripPrefixRegex) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*StripPrefixRegex) SetHandler

func (s *StripPrefixRegex) SetHandler(Handler http.Handler)

SetHandler sets handler

type TLSClientCertificateInfos

type TLSClientCertificateInfos struct {
	Issuer    *DistinguishedNameOptions
	NotAfter  bool
	NotBefore bool
	Sans      bool
	Subject   *DistinguishedNameOptions
}

TLSClientCertificateInfos is a struct for specifying the configuration for the tlsClientHeaders middleware.

type TLSClientHeaders

type TLSClientHeaders struct {
	Infos *TLSClientCertificateInfos // pass selected information from the client certificate
	PEM   bool                       // pass the sanitized pem to the backend in a specific header
}

TLSClientHeaders is a middleware that helps setup a few tls info features.

func NewTLSClientHeaders

func NewTLSClientHeaders(passTLSClientCert *types.TLSClientHeaders) *TLSClientHeaders

NewTLSClientHeaders constructs a new TLSClientHeaders instance from supplied frontend header struct.

func (*TLSClientHeaders) ModifyRequestHeaders

func (s *TLSClientHeaders) ModifyRequestHeaders(r *http.Request)

ModifyRequestHeaders set the wanted headers with the certificates information

func (*TLSClientHeaders) ServeHTTP

func (s *TLSClientHeaders) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Package Files

  • addPrefix.go
  • cbreaker.go
  • compress.go
  • empty_backend_handler.go
  • handlerSwitcher.go
  • headers.go
  • ip_whitelister.go
  • metrics.go
  • recover.go
  • replace_path.go
  • replace_path_regex.go
  • request_host.go
  • retry.go
  • routes.go
  • secure.go
  • stateful.go
  • stats.go
  • stripPrefix.go
  • stripPrefixRegex.go
  • tlsClientHeaders.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier