middlewares

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2018 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const ForwardedPrefixHeader = "X-Forwarded-Prefix"

ForwardedPrefixHeader is the default header to set prefix

View Source
const ReplacedPathHeader = "X-Replaced-Path"

ReplacedPathHeader is the default header to set the old path to

Variables

This section is empty.

Functions

func NegroniRecoverHandler added in v1.3.0

func NegroniRecoverHandler() negroni.Handler

NegroniRecoverHandler recovers from a panic in negroni handlers

func NewBackendMetricsMiddleware added in v1.6.0

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

NewBackendMetricsMiddleware creates a new metrics middleware for a Backend.

func NewCircuitBreakerOptions added in v1.6.0

func NewCircuitBreakerOptions(expression string) cbreaker.CircuitBreakerOption

NewCircuitBreakerOptions returns a new CircuitBreakerOption

func NewEntryPointMetricsMiddleware added in v1.6.0

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

NewEntryPointMetricsMiddleware creates a new metrics middleware for an Entrypoint.

func NewReplacePathRegexHandler added in v1.5.0

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

NewReplacePathRegexHandler returns a new ReplacePathRegex

func NewSecure added in v1.4.0

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

NewSecure constructs a new Secure instance with supplied options.

func RecoverHandler added in v1.3.0

func RecoverHandler(next http.Handler) http.Handler

RecoverHandler recovers from a panic in http handlers

Types

type AddPrefix added in v1.2.0

type AddPrefix struct {
	Handler http.Handler
	Prefix  string
}

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

func (*AddPrefix) ServeHTTP added in v1.2.0

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

func (*AddPrefix) SetHandler added in v1.2.0

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, next http.HandlerFunc)

type Compress added in v1.1.0

type Compress struct{}

Compress is a middleware that allows redirection

func (*Compress) ServeHTTP added in v1.1.0

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

ServerHTTP is a function used by Negroni

type DefaultNetErrorRecorder added in v1.4.0

type DefaultNetErrorRecorder struct{}

DefaultNetErrorRecorder is the default NetErrorRecorder implementation.

func (DefaultNetErrorRecorder) Record added in v1.4.0

Record is recording network errors by setting the context value for the defaultNetErrCtxKey to true.

type EmptyBackendHandler added in v1.4.0

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 added in v1.4.0

func NewEmptyBackendHandler(lb healthcheck.LoadBalancer, next http.Handler) *EmptyBackendHandler

NewEmptyBackendHandler creates a new EmptyBackendHandler instance.

func (*EmptyBackendHandler) ServeHTTP added in v1.4.0

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 added in v1.4.0

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 added in v1.4.0

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 added in v1.4.0

func NewHeaderFromStruct(headers *types.Headers) *HeaderStruct

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

func (*HeaderStruct) ModifyRequestHeaders added in v1.5.0

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

ModifyRequestHeaders set or delete request headers

func (*HeaderStruct) ModifyResponseHeaders added in v1.5.0

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

ModifyResponseHeaders set or delete response headers

func (*HeaderStruct) ServeHTTP added in v1.4.0

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

type IPWhiteLister added in v1.4.0

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 added in v1.6.0

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

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

func (*IPWhiteLister) ServeHTTP added in v1.4.0

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

type MetricsRetryListener added in v1.4.0

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 added in v1.4.0

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

Retried tracks the retry in the RequestMetrics implementation.

type NetErrorRecorder added in v1.4.0

type NetErrorRecorder interface {
	// Record can be used to signal the retry middleware that an network error happened
	// and therefore the request should be retried.
	Record(ctx context.Context)
}

NetErrorRecorder is an interface to record net errors.

type ReplacePath added in v1.3.0

type ReplacePath struct {
	Handler http.Handler
	Path    string
}

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

func (*ReplacePath) ServeHTTP added in v1.3.0

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

type ReplacePathRegex added in v1.5.0

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 added in v1.5.0

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

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 added in v1.4.0

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 added in v1.4.0

func NewMetricsRetryListener(retryMetrics retryMetrics, backendName string) RetryListener

NewMetricsRetryListener instantiates a MetricsRetryListener with the given retryMetrics.

type RetryListeners added in v1.4.0

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 added in v1.4.0

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 added in v1.3.0

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

type Stats added in v1.2.0

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

Stats includes all of the stats gathered by the recorder.

type StatsRecorder added in v1.2.0

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 added in v1.2.0

func NewStatsRecorder(numRecentErrors int) *StatsRecorder

NewStatsRecorder returns a new StatsRecorder

func (*StatsRecorder) Data added in v1.2.0

func (s *StatsRecorder) Data() *Stats

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

func (*StatsRecorder) ServeHTTP added in v1.2.0

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 added in v1.3.0

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 added in v1.3.0

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

NewStripPrefixRegex builds a new StripPrefixRegex given a handler and prefixes

func (*StripPrefixRegex) ServeHTTP added in v1.3.0

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

func (*StripPrefixRegex) SetHandler added in v1.3.0

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

SetHandler sets handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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