header

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: Apache-2.0 Imports: 14 Imported by: 59

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, and X-Forwarded-Host headers.

If X-Forwarded-For is already present, the client IP is appended to the existing value.

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 NewIDModifier

func NewIDModifier() martian.RequestModifier

NewIDModifier returns a request modifier that will set a header with the name X-Martian-ID with a value that is a unique identifier for the request. In the case that the X-Martian-ID header is already set, the header is unmodified.

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.

type ViaModifier

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

ViaModifier is a header modifier that checks for proxy redirect loops.

func NewViaModifier

func NewViaModifier(requestedBy string) *ViaModifier

NewViaModifier returns a new Via modifier.

func (*ViaModifier) ModifyRequest

func (m *ViaModifier) ModifyRequest(req *http.Request) error

ModifyRequest sets the Via header and provides loop-detection. If Via is already present, it will be appended to the existing value. If a loop is detected an error is added to the context and the request round trip is skipped.

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

func (*ViaModifier) ModifyResponse

func (m *ViaModifier) ModifyResponse(res *http.Response) error

ModifyResponse sets the status code to 400 Bad Request if a loop was detected in the request.

func (*ViaModifier) SetBoundary

func (m *ViaModifier) SetBoundary(boundary string)

SetBoundary sets the boundary string (random 10 character by default) used to disabiguate Martians that are chained together with identical requestedBy values. This should only be used for testing.

Jump to

Keyboard shortcuts

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