skipper: github.com/zalando/skipper/filters/builtin Index | Files

package builtin

import "github.com/zalando/skipper/filters/builtin"

Package builtin provides a small, generic set of filters.

Index

Package Files

builtin.go compress.go copy.go creationmetrics.go dynamicbackendfilter.go headerfilter.go headertoquery.go healthcheck.go inlinecontent.go originmarker.go path.go preservehost.go query.go querytoheader.go redirect.go static.go status.go stripquery.go

Constants

const (
    // Deprecated: use setRequestHeader or appendRequestHeader
    RequestHeaderName = "requestHeader"

    // Deprecated: use setResponseHeader or appendResponseHeader
    ResponseHeaderName = "responseHeader"

    // Deprecated: use redirectTo
    RedirectName = "redirect"

    SetRequestHeaderName     = "setRequestHeader"
    SetResponseHeaderName    = "setResponseHeader"
    AppendRequestHeaderName  = "appendRequestHeader"
    AppendResponseHeaderName = "appendResponseHeader"
    DropRequestHeaderName    = "dropRequestHeader"
    DropResponseHeaderName   = "dropResponseHeader"

    SetDynamicBackendHostFromHeader   = "setDynamicBackendHostFromHeader"
    SetDynamicBackendSchemeFromHeader = "setDynamicBackendSchemeFromHeader"
    SetDynamicBackendUrlFromHeader    = "setDynamicBackendUrlFromHeader"
    SetDynamicBackendHost             = "setDynamicBackendHost"
    SetDynamicBackendScheme           = "setDynamicBackendScheme"
    SetDynamicBackendUrl              = "setDynamicBackendUrl"

    HealthCheckName     = "healthcheck"
    ModPathName         = "modPath"
    SetPathName         = "setPath"
    RedirectToName      = "redirectTo"
    RedirectToLowerName = "redirectToLower"
    StaticName          = "static"
    StripQueryName      = "stripQuery"
    PreserveHostName    = "preserveHost"
    StatusName          = "status"
    CompressName        = "compress"
    SetQueryName        = "setQuery"
    DropQueryName       = "dropQuery"
    InlineContentName   = "inlineContent"
    HeaderToQueryName   = "headerToQuery"
    QueryToHeaderName   = "queryToHeader"
)
const (

    // CopyRequestHeader copies a request header to another proxy
    // request header
    CopyRequestHeader direction = iota
    // CopyResponseHeader copies a proxied response header to the
    // response header
    CopyResponseHeader
)
const (
    OriginMarkerName = "originMarker"
)

func MakeRegistry Uses

func MakeRegistry() filters.Registry

Returns a Registry object initialized with the default set of filter specifications found in the filters package. (including the builtin and the flowid subdirectories.)

func NewAppendRequestHeader Uses

func NewAppendRequestHeader() filters.Spec

Returns a filter specification that is used to append headers for requests. Instances expect two parameters: the header name and the header value. Name: "appendRequestHeader".

If the header name is 'Host', the filter uses the `SetOutgoingHost()` method to set the header in addition to the standard `Request.Header` map.

func NewAppendResponseHeader Uses

func NewAppendResponseHeader() filters.Spec

Returns a filter specification that is used to append headers for responses. Instances expect two parameters: the header name and the header value. Name: "appendResponseHeader".

func NewCompress Uses

func NewCompress() filters.Spec

Returns a filter specification that is used to compress the response content.

Example:

* -> compress() -> "https://www.example.org"

The filter, when executed on the response path, checks if the response entity can be compressed. To decide, it checks the Content-Encoding, the Cache-Control and the Content-Type headers. It doesn't compress the content if the Content-Encoding is set to other than identity, or the Cache-Control applies the no-transform pragma, or the Content-Type is set to an unsupported value.

The default supported content types are: text/plain, text/html, application/json, application/javascript, application/x-javascript, text/javascript, text/css, image/svg+xml, application/octet-stream.

The default set of MIME types can be reset or extended by passing in the desired types as filter arguments. When extending the defaults, the first argument needs to be "...". E.g. to compress tiff in addition to the defaults:

* -> compress("...", "image/tiff") -> "https://www.example.org"

To reset the supported types, e.g. to compress only HTML, the "..." argument needs to be omitted:

* -> compress("text/html") -> "https://www.example.org"

It is possible to control the compression level, by setting it as the first filter argument, in front of the MIME types. The default compression level is best-speed. The possible values are integers between 0 and 9 (inclusive), where 0 means no-compression, 1 means best-speed and 9 means best-compression. Example:

* -> compress(9, "image/tiff") -> "https://www.example.org"

The filter also checks the incoming request, if it accepts the supported encodings, explicitly stated in the Accept-Encoding header. The filter currently supports gzip and deflate. It does not assume that the client accepts any encoding if the Accept-Encoding header is not set. It ignores * in the Accept-Encoding header.

When compressing the response, it updates the response header. It deletes the the Content-Length value triggering the proxy to always return the response with chunked transfer encoding, sets the Content-Encoding to the selected encoding and sets the Vary: Accept-Encoding header, if missing.

The compression happens in a streaming way, using only a small internal buffer.

func NewCopyRequestHeader Uses

func NewCopyRequestHeader() filters.Spec

NewCopyRequestHeader creates a filter specification whose instances copies a specified source Header to a defined destination Header from the request to the proxy request.

func NewCopyResponseHeader Uses

func NewCopyResponseHeader() filters.Spec

NewCopyResponseHeader creates a filter specification whose instances copies a specified source Header to a defined destination Header from the backend response to the proxy response.

func NewDropQuery Uses

func NewDropQuery() filters.Spec

Returns a new dropQuery filter Spec, whose instances drop a corresponding query parameter.

As an EXPERIMENTAL feature: the dropQuery filter provides the possiblity to apply template operations. The current solution supports templates with placeholders of the format: ${param1}, and the placeholders will be replaced with the values of the same name from the wildcards in the Path() predicate. The templating feature will stay in Skipper, but the syntax of the templating may change.

See also: https://github.com/zalando/skipper/issues/182

Name: "dropQuery".

func NewDropRequestHeader Uses

func NewDropRequestHeader() filters.Spec

Returns a filter specification that is used to delete headers for requests. Instances expect one parameter: the header name. Name: "dropRequestHeader".

func NewDropResponseHeader Uses

func NewDropResponseHeader() filters.Spec

Returns a filter specification that is used to delete headers for responses. Instances expect one parameter: the header name. Name: "dropResponseHeader".

func NewHeaderToQuery Uses

func NewHeaderToQuery() filters.Spec

NewHeaderToQuery creates a filter which converts the headers from the incoming Request to query params

headerToQuery("X-Foo-Header", "foo-query-param")

The above filter will set the "foo-query-param" query param to the value of "X-Foo-Header" header, to the request and will override the value if the queryparam exists already

func NewHealthCheck Uses

func NewHealthCheck() filters.Spec

Creates a new filter Spec, whose instances set the status code of the response to 200 OK. Name: "healthcheck".

func NewInlineContent Uses

func NewInlineContent() filters.Spec

Creates a filter spec for the inlineContent() filter.

Usage of the filter:

* -> status(420) -> inlineContent("Enhance Your Calm") -> <shunt>

Or:

* -> inlineContent("{\"foo\": 42}", "application/json") -> <shunt>

It accepts two arguments: the content and the optional content type. When the content type is not set, it tries to detect it using http.DetectContentType.

The filter shunts the request with status code 200.

func NewModPath Uses

func NewModPath() filters.Spec

Returns a new modpath filter Spec, whose instances execute regexp.ReplaceAllString on the request path. Instances expect two parameters: the expression to match and the replacement string. Name: "modpath".

func NewOriginMarker Uses

func NewOriginMarker(origin string, id string, created time.Time) *eskip.Filter

func NewOriginMarkerSpec Uses

func NewOriginMarkerSpec() filters.Spec

NewOriginMarkerSpec creates a filter specification whose instances mark the origin an eskip.Route

func NewQueryToHeader Uses

func NewQueryToHeader() filters.Spec

NewQueryToHeader creates a filter which converts query params from the incoming Request to headers

queryToHeader("foo-query-param", "X-Foo-Header")

The above filter will set the value of "X-Foo-Header" header to the value of "foo-query-param" query param , to the request and will not override the value if the header exists already

The header value can be created by a formatstring with an optional third parameter

queryToHeader("foo-query-param", "X-Foo-Header", "prefix %s postfix")
queryToHeader("access_token", "Authorization", "Bearer %s")

func NewRedirect Uses

func NewRedirect() filters.Spec

NewRedirect returns a new filter Spec, whose instances create an HTTP redirect response. Marks the request as served. Instances expect two parameters: the redirect status code and the redirect location. Name: "redirect".

This filter is deprecated, use RedirectTo instead. This *DEPRECATED* filter can not be used with filters from scheduler package.

func NewRedirectLower Uses

func NewRedirectLower() filters.Spec

NewRedirectLower returns a new filter Spec, whose instances create an HTTP redirect response, which redirects with a lowercase path. It is similar to redTo except that it converts the route path to lower while redirecting Name: "redirectToLower".

func NewRedirectTo Uses

func NewRedirectTo() filters.Spec

NewRedirectTo returns a new filter Spec, whose instances create an HTTP redirect response. It shunts the request flow, meaning that the filter chain on the request path is not continued. The request is not forwarded to the backend. Instances expect two parameters: the redirect status code and the redirect location. Name: "redirectTo".

func NewRequestHeader Uses

func NewRequestHeader() filters.Spec

Deprecated: use setRequestHeader or appendRequestHeader

func NewResponseHeader Uses

func NewResponseHeader() filters.Spec

Deprecated: use setRequestHeader or appendRequestHeader

func NewSetDynamicBackendHost Uses

func NewSetDynamicBackendHost() filters.Spec

Returns a filter specification that is used to set dynamic backend host. Instances expect one parameters: a host name. Name: "setDynamicBackendHost".

The value is put into the `StateBag`, additionally `SetOutgoingHost()` is used to set the host header

func NewSetDynamicBackendHostFromHeader Uses

func NewSetDynamicBackendHostFromHeader() filters.Spec

Returns a filter specification that is used to set dynamic backend host from a header. Instances expect one parameters: a header name. Name: "setDynamicBackendHostFromHeader".

If the header exists the value is put into the `StateBag`, additionally `SetOutgoingHost()` is used to set the host header

func NewSetDynamicBackendScheme Uses

func NewSetDynamicBackendScheme() filters.Spec

Returns a filter specification that is used to set dynamic backend scheme. Instances expect one parameters: a scheme name. Name: "setDynamicBackendScheme".

The value is put into the `StateBag`

func NewSetDynamicBackendSchemeFromHeader Uses

func NewSetDynamicBackendSchemeFromHeader() filters.Spec

Returns a filter specification that is used to set dynamic backend scheme from a header. Instances expect one parameters: a header name. Name: "setDynamicBackendSchemeFromHeader".

If the header exists the value is put into the `StateBag`

func NewSetDynamicBackendUrl Uses

func NewSetDynamicBackendUrl() filters.Spec

Returns a filter specification that is used to set dynamic backend url. Instances expect one parameters: a url. Name: "setDynamicBackendUrl".

The value is put into the `StateBag`, additionally `SetOutgoingHost()` is used to set the host header if the input provided is a valid url

func NewSetDynamicBackendUrlFromHeader Uses

func NewSetDynamicBackendUrlFromHeader() filters.Spec

Returns a filter specification that is used to set dynamic backend url from a header. Instances expect one parameters: a header name. Name: "setDynamicBackendUrlFromHeader".

If the header exists the value is put into the `StateBag`, additionally `SetOutgoingHost()` is used to set the host header if the header is a valid url

func NewSetPath Uses

func NewSetPath() filters.Spec

Returns a new setPath filter Spec, whose instances replace the request path.

As an EXPERIMENTAL feature: the setPath filter provides the possiblity to apply template operations. The current solution supports templates with placeholders of the format: ${param1}, and the placeholders will be replaced with the values of the same name from the wildcards in the Path() predicate.

See: https://godoc.org/github.com/zalando/skipper/routing#hdr-Wildcards

The templating feature will stay in Skipper, but the syntax of the templating may change.

See also: https://github.com/zalando/skipper/issues/182

Instances expect one parameter: the new path to be set, or the path template to be evaluated.

Name: "setPath".

func NewSetQuery Uses

func NewSetQuery() filters.Spec

Returns a new setQuery filter Spec, whose instances replace the query parameters.

As an EXPERIMENTAL feature: the setPath filter provides the possiblity to apply template operations. The current solution supports templates with placeholders of the format: ${param1}, and the placeholders will be replaced with the values of the same name from the wildcards in the Path() predicate.

See: https://godoc.org/github.com/zalando/skipper/routing#hdr-Wildcards

The templating feature will stay in Skipper, but the syntax of the templating may change.

See also: https://github.com/zalando/skipper/issues/182

Instances expect two parameters: the name and the value to be set, either strings or templates are valid.

Name: "setQuery".

func NewSetRequestHeader Uses

func NewSetRequestHeader() filters.Spec

Returns a filter specification that is used to set headers for requests. Instances expect two parameters: the header name and the header value. Name: "setRequestHeader".

If the header name is 'Host', the filter uses the `SetOutgoingHost()` method to set the header in addition to the standard `Request.Header` map.

func NewSetResponseHeader Uses

func NewSetResponseHeader() filters.Spec

Returns a filter specification that is used to set headers for responses. Instances expect two parameters: the header name and the header value. Name: "setResponseHeader".

func NewStatic Uses

func NewStatic() filters.Spec

Returns a filter Spec to serve static content from a file system location. Behaves similarly to net/http.FileServer. It shunts the route.

Filter instances of this specification expect two parameters: a request path prefix and a local directory path. When processing a request, it clips the prefix from the request path, and appends the rest of the path to the directory path. Then, it uses the resulting path to serve static content from the file system.

Name: "static".

func NewStatus Uses

func NewStatus() filters.Spec

Creates a filter specification whose instances set the status of the response to a fixed value regardless of backend response.

func NewStripQuery Uses

func NewStripQuery() filters.Spec

Returns a filter Spec to strip query parameters from the request and optionally transpose them to request headers.

It always removes the query parameter from the request URL, and if the first filter parameter is "true", preserves the query parameter in the form of x-query-param-<queryParamName>: <queryParamValue> headers, so that ?foo=bar becomes x-query-param-foo: bar

Name: "stripQuery".

func PreserveHost Uses

func PreserveHost() filters.Spec

Returns a filter specification whose filter instances are used to override the `proxyPreserveHost` behavior for individual routes.

Instances expect one argument, with the possible values: "true" or "false", where "true" means to use the Host header from the incoming request, and "false" means to use the host from the backend address.

The filter takes no effect in either case if another filter modifies the outgoing host header to a value other than the one in the incoming request or in the backend address.

func Redirect Uses

func Redirect(ctx filters.FilterContext, code int, location *url.URL)

Redirect implements the redirect logic as a standalone function.

type OriginMarker Uses

type OriginMarker struct {
    // the type of origin, e.g. ingress
    Origin string `json:"origin"`
    // the unique ID (within the origin) of the source object (e.g. ingress) that created the route
    Id  string `json:"id"`
    // when the source object was created
    Created time.Time `json:"created"`
}

OriginMarker carries information about the origin of a route

func (OriginMarker) Request Uses

func (m OriginMarker) Request(filters.FilterContext)

func (OriginMarker) Response Uses

func (m OriginMarker) Response(filters.FilterContext)

type RouteCreationMetrics Uses

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

RouteCreationMetrics reports metrics about the time it took to create metrics. It looks for filters of type OriginMarker to determine when the source object (e.g. ingress) of the route was created. If an OriginMarker with the same type and id is seen again, the creation time is not reported again, because a route with the same configuration already existed before.

func NewRouteCreationMetrics Uses

func NewRouteCreationMetrics(metrics filters.Metrics) *RouteCreationMetrics

func (*RouteCreationMetrics) Do Uses

func (m *RouteCreationMetrics) Do(routes []*routing.Route) []*routing.Route

Do implements routing.PostProcessor and records the filter creation time.

Package builtin imports 37 packages (graph) and is imported by 8 packages. Updated 2019-11-12. Refresh now. Tools for package owners.