builtin

package
v0.13.225 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0, MIT Imports: 40 Imported by: 8

Documentation

Overview

Package builtin provides a small, generic set of filters.

Index

Constants

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

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

	// Deprecated: use redirectTo
	RedirectName = "redirect"

	// Deprecated, use filters.SetRequestHeaderName instead
	SetRequestHeaderName = filters.SetRequestHeaderName
	// Deprecated, use filters.SetResponseHeaderName instead
	SetResponseHeaderName = filters.SetResponseHeaderName
	// Deprecated, use filters.AppendRequestHeaderName instead
	AppendRequestHeaderName = filters.AppendRequestHeaderName
	// Deprecated, use filters.AppendResponseHeaderName instead
	AppendResponseHeaderName = filters.AppendResponseHeaderName
	// Deprecated, use filters.DropRequestHeaderName instead
	DropRequestHeaderName = filters.DropRequestHeaderName
	// Deprecated, use filters.DropResponseHeaderName instead
	DropResponseHeaderName = filters.DropResponseHeaderName
	// Deprecated, use filters.SetContextRequestHeaderName instead
	SetContextRequestHeaderName = filters.SetContextRequestHeaderName
	// Deprecated, use filters.AppendContextRequestHeaderName instead
	AppendContextRequestHeaderName = filters.AppendContextRequestHeaderName
	// Deprecated, use filters.SetContextResponseHeaderName instead
	SetContextResponseHeaderName = filters.SetContextResponseHeaderName
	// Deprecated, use filters.AppendContextResponseHeaderName instead
	AppendContextResponseHeaderName = filters.AppendContextResponseHeaderName
	// Deprecated, use filters.CopyRequestHeaderName instead
	CopyRequestHeaderName = filters.CopyRequestHeaderName
	// Deprecated, use filters.CopyResponseHeaderName instead
	CopyResponseHeaderName = filters.CopyResponseHeaderName

	// Deprecated, use filters.SetDynamicBackendHostFromHeader instead
	SetDynamicBackendHostFromHeader = filters.SetDynamicBackendHostFromHeader
	// Deprecated, use filters.SetDynamicBackendSchemeFromHeader instead
	SetDynamicBackendSchemeFromHeader = filters.SetDynamicBackendSchemeFromHeader
	// Deprecated, use filters.SetDynamicBackendUrlFromHeader instead
	SetDynamicBackendUrlFromHeader = filters.SetDynamicBackendUrlFromHeader
	// Deprecated, use filters.SetDynamicBackendHost instead
	SetDynamicBackendHost = filters.SetDynamicBackendHost
	// Deprecated, use filters.SetDynamicBackendScheme instead
	SetDynamicBackendScheme = filters.SetDynamicBackendScheme
	// Deprecated, use filters.SetDynamicBackendUrl instead
	SetDynamicBackendUrl = filters.SetDynamicBackendUrl

	// Deprecated, use filters.HealthCheckName instead
	HealthCheckName = filters.HealthCheckName
	// Deprecated, use filters.ModPathName instead
	ModPathName = filters.ModPathName
	// Deprecated, use filters.SetPathName instead
	SetPathName = filters.SetPathName
	// Deprecated, use filters.ModRequestHeaderName instead
	ModRequestHeaderName = filters.ModRequestHeaderName
	// Deprecated, use filters.RedirectToName instead
	RedirectToName = filters.RedirectToName
	// Deprecated, use filters.RedirectToLowerName instead
	RedirectToLowerName = filters.RedirectToLowerName
	// Deprecated, use filters.StaticName instead
	StaticName = filters.StaticName
	// Deprecated, use filters.StripQueryName instead
	StripQueryName = filters.StripQueryName
	// Deprecated, use filters.PreserveHostName instead
	PreserveHostName = filters.PreserveHostName
	// Deprecated, use filters.SetFastCgiFilenameName instead
	SetFastCgiFilenameName = filters.SetFastCgiFilenameName
	// Deprecated, use filters.StatusName instead
	StatusName = filters.StatusName
	// Deprecated, use filters.CompressName instead
	CompressName = filters.CompressName
	// Deprecated, use filters.SetQueryName instead
	SetQueryName = filters.SetQueryName
	// Deprecated, use filters.DropQueryName instead
	DropQueryName = filters.DropQueryName
	// Deprecated, use filters.InlineContentName instead
	InlineContentName = filters.InlineContentName
	// Deprecated, use filters.InlineContentIfStatusName instead
	InlineContentIfStatusName = filters.InlineContentIfStatusName
	// Deprecated, use filters.HeaderToQueryName instead
	HeaderToQueryName = filters.HeaderToQueryName
	// Deprecated, use filters.QueryToHeaderName instead
	QueryToHeaderName = filters.QueryToHeaderName
	// Deprecated, use filters.BackendTimeoutName instead
	BackendTimeoutName = filters.BackendTimeoutName
)
View Source
const (
	// DecompressionNotPossible is the state-bag key to indicate
	// to the subsequent filters during response processing that the
	// content is compressed, but decompression was not possible, e.g
	// because the encoding is not supported.
	DecompressionNotPossible = "filter::decompress::not-possible"

	// DecompressionError is the state-bag key to indicate to the
	// subsequent filters during response processing that the
	// decompression of the content was attempted but failed. The
	// response body may have been sniffed, and therefore it was
	// discarded.
	DecompressionError = "filter::decompress::error"
)
View Source
const (
	// Deprecated, use filters.OriginMarkerName instead
	OriginMarkerName = filters.OriginMarkerName
)

Variables

This section is empty.

Functions

func MakeRegistry

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 NewAppendContextRequestHeader added in v0.11.80

func NewAppendContextRequestHeader() filters.Spec

NewAppendContextRequestHeader returns a filter specification used to append request headers with a given name and a value taken from the filter context state bag identified by its key.

func NewAppendContextResponseHeader added in v0.11.80

func NewAppendContextResponseHeader() filters.Spec

NewAppendContextResponseHeader returns a filter specification used to append response headers with a given name and a value taken from the filter context state bag identified by its key.

func NewAppendRequestHeader

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 template, see eskip.Template.ApplyContext 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

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 template, see eskip.Template.ApplyContext Name: "appendResponseHeader".

func NewBackendIsProxy added in v0.11.17

func NewBackendIsProxy() filters.Spec

NewBackendIsProxy returns a filter specification that is used to specify that the backend is also a proxy.

func NewBackendTimeout added in v0.12.17

func NewBackendTimeout() filters.Spec

func NewCompress

func NewCompress() filters.Spec

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

Example:

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:

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

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 11 (inclusive), where 0 means no-compression, 1 means best-speed and 11 means best-compression. Example:

The filter also checks the incoming request, if it accepts the supported encodings, explicitly stated in the Accept-Encoding header. The filter currently supports brotli, 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.

Supported encodings are prioritized on: - quality value if provided by client - server side priority (encodingPriority) otherwise

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 NewCompressWithOptions added in v0.13.180

func NewCompressWithOptions(options CompressOptions) (filters.Spec, error)

func NewCopyRequestHeader added in v0.9.141

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 NewCopyRequestHeaderDeprecated added in v0.11.108

func NewCopyRequestHeaderDeprecated() filters.Spec

func NewCopyResponseHeader added in v0.9.141

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 NewCopyResponseHeaderDeprecated added in v0.11.108

func NewCopyResponseHeaderDeprecated() filters.Spec

func NewDecompress added in v0.11.84

func NewDecompress() filters.Spec

NewDecompress creates a filter specification for the decompress() filter. The filter attempts to decompress the response body, if it was compressed with any of deflate, gzip or br.

If decompression is not possible, but the body is compressed, then it indicates it with the "filter::decompress::not-possible" key in the state-bag. If the decompression was attempted and failed to get initialized, it indicates it in addition with the "filter::decompress::error" state-bag key, storing the error. Due to the streaming, decompression may fail after all the filters were processed.

The filter does not need any parameters.

func NewDropQuery

func NewDropQuery() filters.Spec

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

Instances expect the name string or template parameter, see eskip.Template.ApplyContext

Name: "dropQuery".

func NewDropRequestHeader

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

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 added in v0.10.68

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

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 added in v0.9.119

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 NewInlineContentIfStatus added in v0.11.74

func NewInlineContentIfStatus() filters.Spec

Creates a filter spec for the inlineContent() filter.

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

The filter replaces the response coming from the backend or the following filters.

func NewModPath

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 NewModRequestHeader added in v0.11.60

func NewModRequestHeader() filters.Spec

NewModRequestHeader returns a new filter Spec, whose instances execute regexp.ReplaceAllString on the request host. Instances expect three parameters: the header name, the expression to match and the replacement string. Name: "modRequestHeader".

func NewOriginMarker added in v0.10.280

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

func NewOriginMarkerSpec added in v0.10.280

func NewOriginMarkerSpec() filters.Spec

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

func NewQueryToHeader added in v0.10.68

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

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 added in v0.9.119

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

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 deprecated

func NewRequestHeader() filters.Spec

Deprecated: use setRequestHeader or appendRequestHeader

func NewResponseHeader deprecated

func NewResponseHeader() filters.Spec

Deprecated: use setRequestHeader or appendRequestHeader

func NewSetContextRequestHeader added in v0.11.80

func NewSetContextRequestHeader() filters.Spec

NewSetContextRequestHeader returns a filter specification used to set request headers with a given name and a value taken from the filter context state bag identified by its key.

func NewSetContextResponseHeader added in v0.11.80

func NewSetContextResponseHeader() filters.Spec

NewSetContextResponseHeader returns a filter specification used to set response headers with a given name and a value taken from the filter context state bag identified by its key.

func NewSetDynamicBackendHost added in v0.10.160

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 added in v0.10.160

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 added in v0.10.160

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 added in v0.10.160

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 added in v0.10.160

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 added in v0.10.160

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 NewSetFastCgiFilename added in v0.11.70

func NewSetFastCgiFilename() filters.Spec

NewSetFastCgiFilename returns a filter spec that makes it possible to change the FastCGI filename.

func NewSetPath

func NewSetPath() filters.Spec

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

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

Name: "setPath".

func NewSetQuery

func NewSetQuery() filters.Spec

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

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

Name: "setQuery".

func NewSetRequestHeader

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 template, see eskip.Template.ApplyContext 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

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 template, see eskip.Template.ApplyContext Name: "setResponseHeader".

func NewStatic

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

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

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

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

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

Redirect implements the redirect logic as a standalone function.

Types

type CompressOptions added in v0.13.180

type CompressOptions struct {
	// Specifies encodings supported for compression, the order defines priority when Accept-Header has equal quality values, see RFC 7231 section 5.3.1
	Encodings []string
}

type OriginMarker added in v0.10.280

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 added in v0.10.280

func (m OriginMarker) Request(filters.FilterContext)

func (OriginMarker) Response added in v0.10.280

func (m OriginMarker) Response(filters.FilterContext)

type RouteCreationMetrics added in v0.10.280

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 added in v0.10.280

func NewRouteCreationMetrics(metrics filters.Metrics) *RouteCreationMetrics

func (*RouteCreationMetrics) Do added in v0.10.280

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

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

Jump to

Keyboard shortcuts

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