Documentation ¶
Overview ¶
Package proxy provides proxy and proxy middleware interfaces and implementations.
Index ¶
- Constants
- Variables
- func AllowlistPrune(wlDict, inDict map[string]interface{}) bool
- func CloneRequestHeaders(headers map[string][]string) map[string][]string
- func CloneRequestParams(params map[string]string) map[string]string
- func NewReadCloserWrapper(ctx context.Context, in io.ReadCloser) io.Reader
- func RegisterResponseCombiner(name string, f ResponseCombiner)
- type BackendFactory
- type EntityFormatter
- type EntityFormatterFunc
- type Factory
- func DefaultFactory(logger logging.Logger) Factory
- func DefaultFactoryWithSubscriber(logger logging.Logger, sF sd.SubscriberFactory) Factory
- func NewDefaultFactory(backendFactory BackendFactory, logger logging.Logger) Factory
- func NewDefaultFactoryWithSubscriber(backendFactory BackendFactory, logger logging.Logger, sF sd.SubscriberFactory) Factory
- func NewShadowFactory(f Factory) Factory
- type FactoryFunc
- type HTTPResponseParser
- type HTTPResponseParserConfig
- type HTTPResponseParserFactory
- type Metadata
- type Middleware
- func NewBackendPluginMiddleware(logger logging.Logger, remote *config.Backend) Middleware
- func NewConcurrentMiddleware(remote *config.Backend) Middleware
- func NewConcurrentMiddlewareWithLogger(logger logging.Logger, remote *config.Backend) Middleware
- func NewFilterHeadersMiddleware(logger logging.Logger, remote *config.Backend) Middleware
- func NewFilterQueryStringsMiddleware(logger logging.Logger, remote *config.Backend) Middleware
- func NewFlatmapMiddleware(logger logging.Logger, cfg *config.EndpointConfig) Middleware
- func NewGraphQLMiddleware(logger logging.Logger, remote *config.Backend) Middleware
- func NewLoadBalancedMiddleware(remote *config.Backend) Middleware
- func NewLoadBalancedMiddlewareWithLogger(l logging.Logger, remote *config.Backend) Middleware
- func NewLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware
- func NewLoadBalancedMiddlewareWithSubscriberAndLogger(l logging.Logger, subscriber sd.Subscriber) Middleware
- func NewLoggingMiddleware(logger logging.Logger, name string) Middleware
- func NewMergeDataMiddleware(logger logging.Logger, endpointConfig *config.EndpointConfig) Middleware
- func NewPluginMiddleware(logger logging.Logger, endpoint *config.EndpointConfig) Middleware
- func NewRandomLoadBalancedMiddleware(remote *config.Backend) Middleware
- func NewRandomLoadBalancedMiddlewareWithLogger(l logging.Logger, remote *config.Backend) Middleware
- func NewRandomLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware
- func NewRandomLoadBalancedMiddlewareWithSubscriberAndLogger(l logging.Logger, subscriber sd.Subscriber) Middleware
- func NewRequestBuilderMiddlewareWithLogger(logger logging.Logger, remote *config.Backend) Middleware
- func NewRoundRobinLoadBalancedMiddleware(remote *config.Backend) Middleware
- func NewRoundRobinLoadBalancedMiddlewareWithLogger(l logging.Logger, remote *config.Backend) Middleware
- func NewRoundRobinLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware
- func NewRoundRobinLoadBalancedMiddlewareWithSubscriberAndLogger(l logging.Logger, subscriber sd.Subscriber) Middleware
- func NewStaticMiddleware(logger logging.Logger, endpointConfig *config.EndpointConfig) Middleware
- type Proxy
- func EmptyMiddleware(next ...Proxy) Proxy
- func EmptyMiddlewareWithLogger(logger logging.Logger, next ...Proxy) Proxy
- func NewHTTPProxy(remote *config.Backend, cf client.HTTPClientFactory, decode encoding.Decoder) Proxy
- func NewHTTPProxyDetailed(_ *config.Backend, re client.HTTPRequestExecutor, ch client.HTTPStatusHandler, ...) Proxy
- func NewHTTPProxyWithHTTPExecutor(remote *config.Backend, re client.HTTPRequestExecutor, dec encoding.Decoder) Proxy
- func NewShadowProxy(p1, p2 Proxy) Proxy
- func NewShadowProxyWithTimeout(timeout time.Duration, p1, p2 Proxy) Proxy
- func ShadowMiddleware(next ...Proxy) Proxy
- func ShadowMiddlewareWithLogger(logger logging.Logger, next ...Proxy) Proxy
- func ShadowMiddlewareWithTimeout(timeout time.Duration, next ...Proxy) Proxy
- func ShadowMiddlewareWithTimeoutAndLogger(logger logging.Logger, timeout time.Duration, next ...Proxy) Proxy
- type Register
- type Request
- type RequestWrapper
- type Response
- type ResponseCombiner
- type ResponseWrapper
Constants ¶
const Namespace = "github.com/devopsfaith/krakend/proxy"
Namespace to be used in extra config
Variables ¶
var ( // ErrNoBackends is the error returned when an endpoint has no backends defined ErrNoBackends = errors.New("all endpoints must have at least one backend") // ErrTooManyBackends is the error returned when an endpoint has too many backends defined ErrTooManyBackends = errors.New("too many backends for this proxy") // ErrTooManyProxies is the error returned when a middleware has too many proxies defined ErrTooManyProxies = errors.New("too many proxies for this proxy middleware") // ErrNotEnoughProxies is the error returned when an endpoint has not enough proxies defined ErrNotEnoughProxies = errors.New("not enough proxies for this endpoint") )
var DefaultHTTPResponseParserConfig = HTTPResponseParserConfig{ func(_ io.Reader, _ *map[string]interface{}) error { return nil }, EntityFormatterFunc(func(r Response) Response { return r }), }
DefaultHTTPResponseParserConfig defines a default HTTPResponseParserConfig
var NewRequestBuilderMiddleware = func(remote *config.Backend) Middleware { return newRequestBuilderMiddleware(logging.NoOp, remote) }
NewRequestBuilderMiddleware creates a proxy middleware that parses the request params received from the outer layer and generates the path to the backend endpoints
Functions ¶
func AllowlistPrune ¶
func CloneRequestHeaders ¶
CloneRequestHeaders returns a copy of the received request headers
func CloneRequestParams ¶
CloneRequestParams returns a copy of the received request params
func NewReadCloserWrapper ¶
NewReadCloserWrapper Creates a new closeable io.Read
func RegisterResponseCombiner ¶
func RegisterResponseCombiner(name string, f ResponseCombiner)
RegisterResponseCombiner adds a new response combiner into the internal register
Types ¶
type BackendFactory ¶
BackendFactory creates a proxy based on the received backend configuration
func CustomHTTPProxyFactory ¶
func CustomHTTPProxyFactory(cf client.HTTPClientFactory) BackendFactory
CustomHTTPProxyFactory returns a BackendFactory. The Proxies it creates will use the received HTTPClientFactory
func HTTPProxyFactory ¶
func HTTPProxyFactory(client *http.Client) BackendFactory
HTTPProxyFactory returns a BackendFactory. The Proxies it creates will use the received net/http.Client
type EntityFormatter ¶
EntityFormatter formats the response data
func NewEntityFormatter ¶
func NewEntityFormatter(remote *config.Backend) EntityFormatter
NewEntityFormatter creates an entity formatter with the received backend definition
type EntityFormatterFunc ¶
EntityFormatterFunc holds the formatter function
func (EntityFormatterFunc) Format ¶
func (e EntityFormatterFunc) Format(entity Response) Response
Format implements the EntityFormatter interface
type Factory ¶
type Factory interface {
New(cfg *config.EndpointConfig) (Proxy, error)
}
Factory creates proxies based on the received endpoint configuration.
Both, factories and backend factories, create proxies but factories are designed as a stack makers because they are intended to generate the complete proxy stack for a given frontend endpoint the app would expose and they could wrap several proxies provided by a backend factory
func DefaultFactory ¶
DefaultFactory returns a default http proxy factory with the injected logger
func DefaultFactoryWithSubscriber ¶
func DefaultFactoryWithSubscriber(logger logging.Logger, sF sd.SubscriberFactory) Factory
DefaultFactoryWithSubscriber returns a default proxy factory with the injected logger and subscriber factory
func NewDefaultFactory ¶
func NewDefaultFactory(backendFactory BackendFactory, logger logging.Logger) Factory
NewDefaultFactory returns a default proxy factory with the injected proxy builder and logger
func NewDefaultFactoryWithSubscriber ¶
func NewDefaultFactoryWithSubscriber(backendFactory BackendFactory, logger logging.Logger, sF sd.SubscriberFactory) Factory
NewDefaultFactoryWithSubscriber returns a default proxy factory with the injected proxy builder, logger and subscriber factory
func NewShadowFactory ¶
NewShadowFactory creates a new shadowFactory using the provided Factory
type FactoryFunc ¶
type FactoryFunc func(*config.EndpointConfig) (Proxy, error)
FactoryFunc type is an adapter to allow the use of ordinary functions as proxy factories. If f is a function with the appropriate signature, FactoryFunc(f) is a Factory that calls f.
func (FactoryFunc) New ¶
func (f FactoryFunc) New(cfg *config.EndpointConfig) (Proxy, error)
New implements the Factory interface
type HTTPResponseParser ¶
HTTPResponseParser defines how the response is parsed from http.Response to Response object
func DefaultHTTPResponseParserFactory ¶
func DefaultHTTPResponseParserFactory(cfg HTTPResponseParserConfig) HTTPResponseParser
DefaultHTTPResponseParserFactory is the default implementation of HTTPResponseParserFactory
type HTTPResponseParserConfig ¶
type HTTPResponseParserConfig struct { Decoder encoding.Decoder EntityFormatter EntityFormatter }
HTTPResponseParserConfig contains the config for a given HttpResponseParser
type HTTPResponseParserFactory ¶
type HTTPResponseParserFactory func(HTTPResponseParserConfig) HTTPResponseParser
HTTPResponseParserFactory creates HTTPResponseParser from a given HTTPResponseParserConfig
type Middleware ¶
Middleware adds a middleware, decorator or wrapper over a collection of proxies, exposing a proxy interface.
Proxy middlewares can be stacked:
var p Proxy p := EmptyMiddleware(NoopProxy) response, err := p(ctx, r)
func NewBackendPluginMiddleware ¶
func NewBackendPluginMiddleware(logger logging.Logger, remote *config.Backend) Middleware
NewBackendPluginMiddleware returns a backend middleware wrapped (if required) with the plugin middleware. The plugin middleware will try to load all the required plugins from the register and execute them in order. RequestModifiers are executed before passing the request to the next middlware. ResponseModifiers are executed once the response is returned from the next middleware.
func NewConcurrentMiddleware ¶
func NewConcurrentMiddleware(remote *config.Backend) Middleware
NewConcurrentMiddlewareWithLogger creates a proxy middleware that enables sending several requests concurrently. Is recommended to use the version with a logger param.
func NewConcurrentMiddlewareWithLogger ¶ added in v2.4.0
func NewConcurrentMiddlewareWithLogger(logger logging.Logger, remote *config.Backend) Middleware
NewConcurrentMiddlewareWithLogger creates a proxy middleware that enables sending several requests concurrently
func NewFilterHeadersMiddleware ¶ added in v2.3.0
func NewFilterHeadersMiddleware(logger logging.Logger, remote *config.Backend) Middleware
NewFilterHeadersMiddleware returns a middleware with or without a header filtering proxy wrapping the next element (depending on the configuration).
func NewFilterQueryStringsMiddleware ¶ added in v2.4.0
func NewFilterQueryStringsMiddleware(logger logging.Logger, remote *config.Backend) Middleware
NewFilterQueryStringsMiddleware returns a middleware with or without a header filtering proxy wrapping the next element (depending on the configuration).
func NewFlatmapMiddleware ¶
func NewFlatmapMiddleware(logger logging.Logger, cfg *config.EndpointConfig) Middleware
NewFlatmapMiddleware creates a proxy middleware that enables applying flatmap operations to the proxy response
func NewGraphQLMiddleware ¶
func NewGraphQLMiddleware(logger logging.Logger, remote *config.Backend) Middleware
NewGraphQLMiddleware returns a middleware with or without the GraphQL proxy wrapping the next element (depending on the configuration). It supports both queries and mutations. For queries, it completes the variables object using the request params. For mutations, it overides the defined variables with the request body. The resulting request will have a proper graphql body with the query and the variables
func NewLoadBalancedMiddleware ¶
func NewLoadBalancedMiddleware(remote *config.Backend) Middleware
NewLoadBalancedMiddleware creates proxy middleware adding the most perfomant balancer over a default subscriber
func NewLoadBalancedMiddlewareWithLogger ¶ added in v2.4.0
func NewLoadBalancedMiddlewareWithLogger(l logging.Logger, remote *config.Backend) Middleware
NewLoadBalancedMiddlewareWithLogger creates proxy middleware adding the most perfomant balancer over a default subscriber
func NewLoadBalancedMiddlewareWithSubscriber ¶
func NewLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware
NewLoadBalancedMiddlewareWithSubscriber creates proxy middleware adding the most perfomant balancer over the received subscriber
func NewLoadBalancedMiddlewareWithSubscriberAndLogger ¶ added in v2.4.0
func NewLoadBalancedMiddlewareWithSubscriberAndLogger(l logging.Logger, subscriber sd.Subscriber) Middleware
NewLoadBalancedMiddlewareWithSubscriberAndLogger creates proxy middleware adding the most perfomant balancer over the received subscriber
func NewLoggingMiddleware ¶
func NewLoggingMiddleware(logger logging.Logger, name string) Middleware
NewLoggingMiddleware creates proxy middleware for logging requests and responses
func NewMergeDataMiddleware ¶
func NewMergeDataMiddleware(logger logging.Logger, endpointConfig *config.EndpointConfig) Middleware
NewMergeDataMiddleware creates proxy middleware for merging responses from several backends
func NewPluginMiddleware ¶
func NewPluginMiddleware(logger logging.Logger, endpoint *config.EndpointConfig) Middleware
NewPluginMiddleware returns an endpoint middleware wrapped (if required) with the plugin middleware. The plugin middleware will try to load all the required plugins from the register and execute them in order. RequestModifiers are executed before passing the request to the next middlware. ResponseModifiers are executed once the response is returned from the next middleware.
func NewRandomLoadBalancedMiddleware ¶
func NewRandomLoadBalancedMiddleware(remote *config.Backend) Middleware
NewRandomLoadBalancedMiddleware creates proxy middleware adding a random balancer over a default subscriber
func NewRandomLoadBalancedMiddlewareWithLogger ¶ added in v2.4.0
func NewRandomLoadBalancedMiddlewareWithLogger(l logging.Logger, remote *config.Backend) Middleware
NewRandomLoadBalancedMiddlewareWithLogger creates proxy middleware adding a random balancer over a default subscriber
func NewRandomLoadBalancedMiddlewareWithSubscriber ¶
func NewRandomLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware
NewRandomLoadBalancedMiddlewareWithSubscriber creates proxy middleware adding a random balancer over the received subscriber
func NewRandomLoadBalancedMiddlewareWithSubscriberAndLogger ¶ added in v2.4.0
func NewRandomLoadBalancedMiddlewareWithSubscriberAndLogger(l logging.Logger, subscriber sd.Subscriber) Middleware
NewRandomLoadBalancedMiddlewareWithSubscriberAndLogger creates proxy middleware adding a random balancer over the received subscriber
func NewRequestBuilderMiddlewareWithLogger ¶ added in v2.4.0
func NewRequestBuilderMiddlewareWithLogger(logger logging.Logger, remote *config.Backend) Middleware
func NewRoundRobinLoadBalancedMiddleware ¶
func NewRoundRobinLoadBalancedMiddleware(remote *config.Backend) Middleware
NewRoundRobinLoadBalancedMiddleware creates proxy middleware adding a round robin balancer over a default subscriber
func NewRoundRobinLoadBalancedMiddlewareWithLogger ¶ added in v2.4.0
func NewRoundRobinLoadBalancedMiddlewareWithLogger(l logging.Logger, remote *config.Backend) Middleware
NewRoundRobinLoadBalancedMiddlewareWithLogger creates proxy middleware adding a round robin balancer over a default subscriber
func NewRoundRobinLoadBalancedMiddlewareWithSubscriber ¶
func NewRoundRobinLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware
NewRoundRobinLoadBalancedMiddlewareWithSubscriber creates proxy middleware adding a round robin balancer over the received subscriber
func NewRoundRobinLoadBalancedMiddlewareWithSubscriberAndLogger ¶ added in v2.4.0
func NewRoundRobinLoadBalancedMiddlewareWithSubscriberAndLogger(l logging.Logger, subscriber sd.Subscriber) Middleware
NewRoundRobinLoadBalancedMiddlewareWithSubscriberAndLogger creates proxy middleware adding a round robin balancer over the received subscriber
func NewStaticMiddleware ¶
func NewStaticMiddleware(logger logging.Logger, endpointConfig *config.EndpointConfig) Middleware
NewStaticMiddleware creates proxy middleware for adding static values to the processed responses
type Proxy ¶
Proxy processes a request in a given context and returns a response and an error
func EmptyMiddleware ¶
func EmptyMiddlewareWithLogger ¶ added in v2.4.0
EmptyMiddlewareWithLoggger is a dummy middleware, useful for testing and fallback
func NewHTTPProxy ¶
func NewHTTPProxy(remote *config.Backend, cf client.HTTPClientFactory, decode encoding.Decoder) Proxy
NewHTTPProxy creates a http proxy with the injected configuration, HTTPClientFactory and Decoder
func NewHTTPProxyDetailed ¶
func NewHTTPProxyDetailed(_ *config.Backend, re client.HTTPRequestExecutor, ch client.HTTPStatusHandler, rp HTTPResponseParser) Proxy
NewHTTPProxyDetailed creates a http proxy with the injected configuration, HTTPRequestExecutor, Decoder and HTTPResponseParser
func NewHTTPProxyWithHTTPExecutor ¶
func NewHTTPProxyWithHTTPExecutor(remote *config.Backend, re client.HTTPRequestExecutor, dec encoding.Decoder) Proxy
NewHTTPProxyWithHTTPExecutor creates a http proxy with the injected configuration, HTTPRequestExecutor and Decoder
func NewShadowProxy ¶
NewShadowProxy returns a Proxy that sends requests to p1 and p2 but ignores the response of p2.
func NewShadowProxyWithTimeout ¶ added in v2.2.4
NewShadowProxyWithTimeout returns a Proxy that sends requests to p1 and p2 but ignores the response of p2. Sets a timeout in the context.
func ShadowMiddleware ¶
ShadowMiddleware is a Middleware that creates a shadowProxy
func ShadowMiddlewareWithLogger ¶ added in v2.4.0
ShadowMiddlewareWithLogger is a Middleware that creates a shadowProxy
func ShadowMiddlewareWithTimeout ¶ added in v2.2.4
ShadowMiddlewareWithTimeout is a Middleware that creates a shadowProxy with a timeout in the context
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
func NewRegister ¶
func NewRegister() *Register
func (Register) GetResponseCombiner ¶
func (r Register) GetResponseCombiner(name string) (ResponseCombiner, bool)
func (Register) SetResponseCombiner ¶
func (r Register) SetResponseCombiner(name string, rc ResponseCombiner)
type Request ¶
type Request struct { Method string URL *url.URL Query url.Values Path string Body io.ReadCloser Params map[string]string Headers map[string][]string }
Request contains the data to send to the backend
func CloneRequest ¶
CloneRequest returns a deep copy of the received request, so the received and the returned proxy.Request do not share a pointer
func (*Request) Clone ¶
Clone clones itself into a new request. The returned cloned request is not thread-safe, so changes on request.Params and request.Headers could generate race-conditions depending on the part of the pipe they are being executed. For thread-safe request headers and/or params manipulation, use the proxy.CloneRequest function.
func (*Request) GeneratePath ¶
GeneratePath takes a pattern and updates the path of the request
type RequestWrapper ¶
type RequestWrapper interface { Params() map[string]string Headers() map[string][]string Body() io.ReadCloser Method() string URL() *url.URL Query() url.Values Path() string }
RequestWrapper is an interface for passing proxy request between the lura pipe and the loaded plugins
type Response ¶
Response is the entity returned by the proxy
func NoOpHTTPResponseParser ¶
NoOpHTTPResponseParser is a HTTPResponseParser implementation that just copies the http response body into the proxy response IO
type ResponseCombiner ¶
ResponseCombiner func to merge the collected responses into a single one
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package plugin provides tools for loading and registering proxy plugins
|
Package plugin provides tools for loading and registering proxy plugins |