martian: Index | Files

package header

import ""

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


Package Files

copy_modifier.go forwarded_modifier.go framing_modifier.go header_append_modifier.go header_blacklist_modifier.go header_filter.go header_matcher.go header_modifier.go header_value_regex_filter.go header_verifier.go hopbyhop_modifier.go id_modifier.go via_modifier.go

func NewAppendModifier Uses

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 Uses

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.

func NewBlacklistModifier Uses

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 Uses

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 Uses

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:

func NewHopByHopModifier Uses

func NewHopByHopModifier() martian.RequestResponseModifier

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

func NewIDModifier Uses

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 Uses

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 Uses

func NewVerifier(name, value string) verify.RequestResponseVerifier

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

type Filter Uses

type Filter struct {

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

func NewFilter Uses

func NewFilter(name, value string) *Filter

NewFilter builds a new header filter.

type Matcher Uses

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 Uses

func NewMatcher(name, value string) *Matcher

NewMatcher builds a new header matcher.

func (*Matcher) MatchRequest Uses

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 Uses

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 Uses

type ValueRegexFilter struct {
    // contains filtered or unexported fields

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

func NewValueRegexFilter Uses

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

NewValueRegexFilter builds a new header value regex filter.

func (*ValueRegexFilter) ModifyRequest Uses

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

ModifyRequest runs reqmod iff the value of header matches regex.

func (*ValueRegexFilter) ModifyResponse Uses

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

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

func (*ValueRegexFilter) SetRequestModifier Uses

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

SetRequestModifier sets the request modifier of HeaderValueRegexFilter.

func (*ValueRegexFilter) SetResponseModifier Uses

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

SetResponseModifier sets the response modifier of HeaderValueRegexFilter.

type ViaModifier Uses

type ViaModifier struct {
    // contains filtered or unexported fields

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

func NewViaModifier Uses

func NewViaModifier(requestedBy string) *ViaModifier

NewViaModifier returns a new Via modifier.

func (*ViaModifier) ModifyRequest Uses

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.

func (*ViaModifier) ModifyResponse Uses

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 Uses

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.

Package header imports 14 packages (graph) and is imported by 4 packages. Updated 2019-07-19. Refresh now. Tools for package owners.