header

package
v1.2.3-sp3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: AGPL-3.0, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package header provides utilities for modifying, filtering, and verifying headers in martian.Proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAppendModifier

func NewAppendModifier(name, value string) martian.RequestResponseModifier

NewAppendModifier returns an appendModifier that will append a header with with the given name and value for both requests and responses. Existing headers with the same name will be left in place.

func NewBadFramingModifier

func NewBadFramingModifier() martian.RequestModifier

NewBadFramingModifier makes a best effort to fix inconsistencies in the request such as multiple Content-Lengths or the lack of Content-Length and improper Transfer-Encoding. If it is unable to determine a proper resolution it returns an error.

http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-3.3

func NewBlacklistModifier

func NewBlacklistModifier(names ...string) martian.RequestResponseModifier

NewBlacklistModifier returns a modifier that will delete any header that matches a name contained in the names parameter.

func NewCopyModifier

func NewCopyModifier(from, to string) martian.RequestResponseModifier

NewCopyModifier returns a modifier that will copy the header in from to the header in to.

func NewForwardedModifier

func NewForwardedModifier() martian.RequestModifier

NewForwardedModifier sets the X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-Host, and X-Forwarded-Url headers.

If X-Forwarded-For is already present, the client IP is appended to the existing value. X-Forwarded-Proto, X-Forwarded-Host, and X-Forwarded-Url are preserved if already present.

TODO: Support "Forwarded" header. see: http://tools.ietf.org/html/rfc7239

func NewHopByHopModifier

func NewHopByHopModifier() martian.RequestResponseModifier

NewHopByHopModifier removes Hop-By-Hop headers from requests and responses.

func NewModifier

func NewModifier(name, value string) martian.RequestResponseModifier

NewModifier returns a modifier that will set the header at name with the given value for both requests and responses. If the header name already exists all values will be overwritten.

func NewVerifier

func NewVerifier(name, value string) verify.RequestResponseVerifier

NewVerifier creates a new header verifier for the given name and value.

Types

type Filter

type Filter struct {
	*filter.Filter
}

Filter filters requests and responses based on header name and value.

func NewFilter

func NewFilter(name, value string) *Filter

NewFilter builds a new header filter.

type Matcher

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

Matcher is a conditonal evalutor of request or response headers to be used in structs that take conditions.

func NewMatcher

func NewMatcher(name, value string) *Matcher

NewMatcher builds a new header matcher.

func (*Matcher) MatchRequest

func (m *Matcher) MatchRequest(req *http.Request) bool

MatchRequest evaluates a request and returns whether or not the request contains a header that matches the provided name and value.

func (*Matcher) MatchResponse

func (m *Matcher) MatchResponse(res *http.Response) bool

MatchResponse evaluates a response and returns whether or not the response contains a header that matches the provided name and value.

type ValueRegexFilter

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

ValueRegexFilter executes resmod and reqmod when the header value matches regex.

func NewValueRegexFilter

func NewValueRegexFilter(regex *regexp.Regexp, header string) *ValueRegexFilter

NewValueRegexFilter builds a new header value regex filter.

func (*ValueRegexFilter) ModifyRequest

func (f *ValueRegexFilter) ModifyRequest(req *http.Request) error

ModifyRequest runs reqmod iff the value of header matches regex.

func (*ValueRegexFilter) ModifyResponse

func (f *ValueRegexFilter) ModifyResponse(res *http.Response) error

ModifyResponse runs resmod iff the value of request header matches regex.

func (*ValueRegexFilter) SetRequestModifier

func (f *ValueRegexFilter) SetRequestModifier(reqmod martian.RequestModifier)

SetRequestModifier sets the request modifier of HeaderValueRegexFilter.

func (*ValueRegexFilter) SetResponseModifier

func (f *ValueRegexFilter) SetResponseModifier(resmod martian.ResponseModifier)

SetResponseModifier sets the response modifier of HeaderValueRegexFilter.

Jump to

Keyboard shortcuts

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