filters

package
v0.0.0-...-e927470 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: Apache-2.0 Imports: 7 Imported by: 5 modules, 36 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Intercept

func Intercept(handler http.Handler, filter Filter) http.Handler

Intercept returns a Handler that intercepts the specified Handler with the given Filter.

Types

type Chain

type Chain []Filter

Chain is a chain of Filters that acts as an http.Handler.

func Join

func Join(filters ...Filter) Chain

Join constructs a new chain of filters that executes the filters in order until it encounters a filter that returns false.

func (Chain) Append

func (c Chain) Append(post ...Filter) Chain

Append creates a new Chain by appending the given filters.

func (Chain) Apply

func (c Chain) Apply(ctx Context, req *http.Request, next Next) (*http.Response, Context, error)

Apply implements the interface Filter

func (Chain) Prepend

func (c Chain) Prepend(pre Filter) Chain

Prepend creates a new chain by prepending the given filter.

type Context

type Context interface {
	context.Context

	// DownstreamConn retrieves the downstream connection from the given Context.
	DownstreamConn() net.Conn

	// RequestNumber indicates how many requests have been received on the current
	// connection. The RequestNumber for the first request is 1, for the second is 2
	// and so forth.
	RequestNumber() int

	// IncrementRequestNumber increments the request number by 1 and returns a new
	// context.
	IncrementRequestNumber() Context

	// WithCancel mimics the method on context.Context
	WithCancel() (Context, context.CancelFunc)

	// WithDeadline mimics the method on context.Context
	WithDeadline(deadline time.Time) (Context, context.CancelFunc)

	// WithTimeout mimics the method on context.Context
	WithTimeout(timeout time.Duration) (Context, context.CancelFunc)

	// WithMITMing marks this context as being part of an MITM'ed connection.
	WithMITMing() Context

	// IsMITMing indicates whether or the proxy is MITMing the current connection.
	IsMITMing() bool

	// WithValue mimics the method on context.Context
	WithValue(key, val interface{}) Context
}

Context is a wrapper for Context that exposes some additional information specific to its use in proxies.

func AdaptContext

func AdaptContext(ctx context.Context) Context

AdaptContext adapts a context.Context to the Context interface.

func BackgroundContext

func BackgroundContext() Context

BackgroundContext creates a background Context without an associated connection.

func Discard

func Discard(ctx Context, req *http.Request) (*http.Response, Context, error)

Discard discards the given request. Make sure to use this when discarding requests in order to make sure that the request body is read.

func Fail

func Fail(ctx Context, req *http.Request, statusCode int, err error) (*http.Response, Context, error)

Fail fails processing, returning a response with the given status code and description populated from error.

func ShortCircuit

func ShortCircuit(ctx Context, req *http.Request, resp *http.Response) (*http.Response, Context, error)

ShortCircuit is a convenience method for creating short-circuiting responses.

func WrapContext

func WrapContext(ctx context.Context, downstream net.Conn) Context

WrapContext wraps the given context.Context into a Context containing the given downstream net.Conn.

type Filter

type Filter interface {
	Apply(ctx Context, req *http.Request, next Next) (*http.Response, Context, error)
}

Filter supports intercepting and modifying http requests and responses

type FilterFunc

type FilterFunc func(ctx Context, req *http.Request, next Next) (*http.Response, Context, error)

FilterFunc adapts a function to a Filter

func (FilterFunc) Apply

func (ff FilterFunc) Apply(ctx Context, req *http.Request, next Next) (*http.Response, Context, error)

Apply implements the interface Filter

type Next

type Next func(ctx Context, req *http.Request) (*http.Response, Context, error)

Next is a function that's used to indicate that request processing should continue as usual.

Jump to

Keyboard shortcuts

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