filters

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 5 Imported by: 1

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(cs *ConnectionState, req *http.Request, next Next) (*http.Response, *ConnectionState, 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 ConnectionState

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

ConnectionState holds data about a connection. No data is ever guaranteed to be present - the getter methods, such as ConnectionState.Upstream, may return zero values for missing data.

func Discard

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(cs *ConnectionState, req *http.Request, statusCode int, err error) (*http.Response, *ConnectionState, error)

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

func NewConnectionState

func NewConnectionState(initialReq *http.Request, upstream, downstream net.Conn) *ConnectionState

NewConnectionState creates a new ConnectionState object. Any of the inputs may be nil.

func ShortCircuit

func ShortCircuit(cs *ConnectionState, req *http.Request, resp *http.Response) (*http.Response, *ConnectionState, error)

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

func (*ConnectionState) ClearUpstream

func (cs *ConnectionState) ClearUpstream()

ClearUpstream clears data about the upstream connection such that Upstream and UpstreamAddr return zero values.

func (*ConnectionState) Clone

func (cs *ConnectionState) Clone() *ConnectionState

Clone this object.

func (*ConnectionState) Downstream

func (cs *ConnectionState) Downstream() net.Conn

Downstream returns the downstream connection.

func (*ConnectionState) IncrementRequestNumber

func (cs *ConnectionState) IncrementRequestNumber()

IncrementRequestNumber increments the counter tracking the number of requests on this connection.

func (*ConnectionState) IsMITMing

func (cs *ConnectionState) IsMITMing() bool

IsMITMing returns true if this connection is part of a MITM'd connection.

func (*ConnectionState) OriginalHost

func (cs *ConnectionState) OriginalHost() string

OriginalURLScheme is the value of Host taken from the first request received on this connection.

func (*ConnectionState) OriginalURLHost

func (cs *ConnectionState) OriginalURLHost() string

OriginalURLHost is the value of URL.Host taken from the first request received on this connection.

func (*ConnectionState) OriginalURLScheme

func (cs *ConnectionState) OriginalURLScheme() string

OriginalURLScheme is the value of URL.Scheme taken from the first request received on this connection.

func (*ConnectionState) RequestAwareRequest

func (cs *ConnectionState) RequestAwareRequest() *http.Request

RequestAwareRequest is the request used by RequestAware connections.

func (*ConnectionState) RequestAwareUpstream

func (cs *ConnectionState) RequestAwareUpstream() net.Conn

RequestAwareUpstream is the upstream connection used by RequestAware connections.

func (*ConnectionState) RequestNumber

func (cs *ConnectionState) RequestNumber() int

RequestNumber returns the current request number for this connection.

func (*ConnectionState) SetMITMing

func (cs *ConnectionState) SetMITMing(isMITMing bool)

SetMITMing is used to mark or unmark this connection as part of a MITM'd connection.

func (*ConnectionState) SetRequestAwareRequest

func (cs *ConnectionState) SetRequestAwareRequest(req *http.Request)

SetRequestAwareRequest sets the request used by RequestAware connections.

func (*ConnectionState) SetRequestAwareUpstream

func (cs *ConnectionState) SetRequestAwareUpstream(upstream net.Conn)

SetRequestAwareUpstream sets the upstream connection used by RequestAware connections.

func (*ConnectionState) SetUpstream

func (cs *ConnectionState) SetUpstream(upstream net.Conn)

SetUpstream sets the upstream connection.

func (*ConnectionState) SetUpstreamAddr

func (cs *ConnectionState) SetUpstreamAddr(upstreamAddr string)

SetUpstreamAddr sets the upstream address.

func (*ConnectionState) Upstream

func (cs *ConnectionState) Upstream() net.Conn

Upstream returns the upstream connection.

func (*ConnectionState) UpstreamAddr

func (cs *ConnectionState) UpstreamAddr() string

UpstreamAddr returns the address of the upstream connection.

type Filter

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

Filter supports intercepting and modifying http requests and responses

type FilterFunc

type FilterFunc func(cs *ConnectionState, req *http.Request, next Next) (*http.Response, *ConnectionState, error)

FilterFunc adapts a function to a Filter

func (FilterFunc) Apply

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

Apply implements the interface Filter

type Next

type Next func(cs *ConnectionState, req *http.Request) (*http.Response, *ConnectionState, 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