modifier

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoCache

func NoCache(h http.Handler) http.Handler

NoCache wraps the Handler with a no cache header, replacing the existing headers. Copied from https://stackoverflow.com/a/33881296

Types

type AddHeaderRule

type AddHeaderRule struct {
	Name  string
	Value string
}

AddHeaderRule represents a header entry. Value supports dynamic "${DOMAIN}".

func (*AddHeaderRule) Add

func (rule *AddHeaderRule) Add(host HostDomain, header http.Header)

Add modifies the header by adding a new header entry. Supports dynamic "${DOMAIN}".

type AddRequestCookieRule

type AddRequestCookieRule struct {
	PathMatcher *regexp.Regexp
	CookieAdder CookieAdder
}

AddRequestCookieRule represents a rule for adding a new (request) cookie.

func (*AddRequestCookieRule) AddCookie

func (rule *AddRequestCookieRule) AddCookie(host HostDomain, req *http.Request)

AddCookie modifies the request by adding the cookie specified in this rule. Supports the dynamic rule "${DOMAIN}", so a 2nd-level and 3rd-level domain name is needed.

func (*AddRequestCookieRule) Match

func (rule *AddRequestCookieRule) Match(path string) bool

Match tests whether the path matches this rule.

type CookieAdder

type CookieAdder struct {
	Name  string
	Value string
}

CookieAdder is the cookie to be added. CookieAdder.Value can contain "${DOMAIN}" for current domain name.

func (*CookieAdder) Add

func (adder *CookieAdder) Add(host HostDomain, req *http.Request)

Add modifies the request by adding a new cookie in the header. Supports dynamic "${DOMAIN}" in cookie value.

type DirectedLocation

type DirectedLocation struct {
	Server string
	Scheme string
	Host   string
	Path   string
}

DirectedLocation represents the target location where the router relays to.

type HostDomain

type HostDomain struct {
	// The host name, e.g. "a.b.example.com:8080"
	Host string
	// The 2nd-level domain name, e.g. "example.com"
	Domain2 string
	// The 3rd-level domain name, e.g. "b.example.com"
	Domain3 string
}

HostDomain is a compiled set of domain names of a host.

func CompileHostDomain

func CompileHostDomain(host string) HostDomain

CompileHostDomain parses the host name and extracts domain names. For example, a.b.example.com:8080" --> ("example.com", "b.example.com")

type PatchBodyRule

type PatchBodyRule struct {
	// Matcher is the regex pattern to be replaced
	Matcher *regexp.Regexp
	// Replacer is the replacement text repl (the same as in regex.ReplaceAll),
	// supports "${HOST}" for current host name
	Replacer []byte
}

PatchBodyRule represents a rule to modify a (response) body.

func (*PatchBodyRule) ReplaceAll

func (rule *PatchBodyRule) ReplaceAll(host string, body []byte) []byte

ReplaceAll will search and replace the response body according to the rule.

type PatchHeaderRule

type PatchHeaderRule struct {
	Name     string
	Matcher  *regexp.Regexp
	Replacer string
}

PatchHeaderRule represents a rule for modify an existing header.

func (*PatchHeaderRule) Patch

func (rule *PatchHeaderRule) Patch(host HostDomain, header http.Header)

Patch modifies the header entries that has the same name in the rule, and replace the value according to the rule.

type RequestDispatchRule

type RequestDispatchRule struct {
	PathMatcher  *regexp.Regexp
	PathReplacer string
	DstScheme    string
	DstHost      string
	DstServer    string
}

RequestDispatchRule is a rule to dispatch specific requests.

func (*RequestDispatchRule) Direct

func (rule *RequestDispatchRule) Direct(path string) DirectedLocation

Direct turns a path into an appropriate DirectedLocation for later consumption. Supports the dynamic "${PATH}" in target path.

func (*RequestDispatchRule) Match

func (rule *RequestDispatchRule) Match(path string) bool

Match tells whether the path matches this rule.

type RequestSleepRule added in v0.2.0

type RequestSleepRule struct {
	PathMatcher *regexp.Regexp
	SleepSec    uint
}

RequestSleepRule is a rule to delay requests.

func (*RequestSleepRule) Match added in v0.2.0

func (rule *RequestSleepRule) Match(path string) bool

Match tells whether the path matches this rule.

Jump to

Keyboard shortcuts

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