filters

package
v1.5.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2016 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package filters contains all the http handler chain filters which are not api related.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCORS

func WithCORS(handler http.Handler, allowedOriginPatterns []string, allowedMethods []string, allowedHeaders []string, exposedHeaders []string, allowCredentials string) http.Handler

WithCORS is a simple CORS implementation that wraps an http Handler. Pass nil for allowedMethods and allowedHeaders to use the defaults. If allowedOriginPatterns is empty or nil, no CORS support is installed.

func WithMaxInFlightLimit

func WithMaxInFlightLimit(handler http.Handler, limit int, longRunningRequestCheck LongRunningRequestCheck) http.Handler

WithMaxInFlightLimit limits the number of in-flight requests to buffer size of the passed in channel.

func WithPanicRecovery

func WithPanicRecovery(handler http.Handler, requestContextMapper api.RequestContextMapper) http.Handler

WithPanicRecovery wraps an http Handler to recover and log panics.

func WithTimeout

func WithTimeout(h http.Handler, timeoutFunc func(*http.Request) (timeout <-chan time.Time, msg string)) http.Handler

WithTimeout returns an http.Handler that runs h with a timeout determined by timeoutFunc. The new http.Handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler responds with a 503 Service Unavailable error and the message provided. (If msg is empty, a suitable default message will be sent.) After the handler times out, writes by h to its http.ResponseWriter will return http.ErrHandlerTimeout. If timeoutFunc returns a nil timeout channel, no timeout will be enforced.

func WithTimeoutForNonLongRunningRequests

func WithTimeoutForNonLongRunningRequests(handler http.Handler, longRunning LongRunningRequestCheck) http.Handler

WithTimeoutForNonLongRunningRequests times out non-long-running requests after the time given by globalTimeout.

Types

type LongRunningRequestCheck

type LongRunningRequestCheck func(r *http.Request) bool

LongRunningRequestCheck is a predicate which is true for long-running http requests.

func BasicLongRunningRequestCheck

func BasicLongRunningRequestCheck(pathRegex *regexp.Regexp, queryParams map[string]string) LongRunningRequestCheck

BasicLongRunningRequestCheck pathRegex operates against the url path, the queryParams match is case insensitive. Any one match flags the request. TODO tighten this check to eliminate the abuse potential by malicious clients that start setting queryParameters to bypass the rate limitter. This could be done using a full parse and special casing the bits we need.

Jump to

Keyboard shortcuts

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