remap

package
v6.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 16 Imported by: 15

Documentation

Index

Constants

View Source
const DefaultReplicas = 1024

Variables

View Source
var ErrIPNotAllowed = errors.New("IP not allowed")
View Source
var ErrNoMoreRetries = errors.New("retry num exceeded")
View Source
var ErrRuleNotFound = errors.New("remap rule not found")

Functions

func LoadRemapRules

func LoadRemapRules(path string, pluginConfigLoaders map[string]plugin.LoadFunc, caches map[string]icache.Cache, baseTransport *http.Transport) ([]remapdata.RemapRule, map[string]interface{}, *remapdata.RemapRulesStats, error)

LoadRemapRules returns the loaded rules, the global plugins, the Stats remap rules, and any error

func NewRemappingTransport

func NewRemappingTransport(reqTimeout time.Duration, reqKeepAlive time.Duration, reqMaxIdleConns int, reqIdleConnTimeout time.Duration) *http.Transport

func RequestURI

func RequestURI(r *http.Request, scheme string) string

RequestURI returns the URI of the given request. This must be used, because Go does not populate the scheme of requests that come in from clients.

Types

type HTTPRequestRemapper

type HTTPRequestRemapper interface {
	// Remap returns the remapped request, the matched rule name, whether the requestor's IP is allowed, whether to connection close, whether a match was found, and any error.
	// Remap(r *http.Request, scheme string, failures int) Remapping
	Rules() []remapdata.RemapRule
	RemappingProducer(r *http.Request, scheme string) (*RemappingProducer, error)
	StatRules() remapdata.RemapRulesStats
	PluginCfg() map[string]interface{} // global plugins, outside the individual remap rules
	// PluginSharedCfg returns the plugins_shared, for every remap rule. This gives plugins a chance on startup to precompute data for each remap rule, store it in the Context, and save computation during requests.
	PluginSharedCfg() map[string]map[string]json.RawMessage
}

func LoadRemapper

func LoadRemapper(path string, pluginConfigLoaders map[string]plugin.LoadFunc, caches map[string]icache.Cache, baseTransport *http.Transport) (HTTPRequestRemapper, error)

func NewHTTPRequestRemapper

func NewHTTPRequestRemapper(remap []remapdata.RemapRule, plugins map[string]interface{}, statRules *remapdata.RemapRulesStats) HTTPRequestRemapper

func RemapperToHTTP

func RemapperToHTTP(r Remapper, statRules *remapdata.RemapRulesStats) HTTPRequestRemapper

type HdrModder

type HdrModder interface {
	Mod(h *http.Header)
}

type RemapRuleJSON

type RemapRuleJSON struct {
	remapdata.RemapRuleBase
	TimeoutMS       *int                       `json:"timeout_ms"`
	ParentSelection *string                    `json:"parent_selection"`
	To              []RemapRuleToJSON          `json:"to"`
	Allow           []string                   `json:"allow"`
	Deny            []string                   `json:"deny"`
	RetryCodes      *[]int                     `json:"retry_codes"`
	CacheName       *string                    `json:"cache_name"`
	Plugins         map[string]json.RawMessage `json:"plugins"`
}

type RemapRuleToJSON

type RemapRuleToJSON struct {
	remapdata.RemapRuleToBase
	ProxyURL   *string `json:"proxy_url"`
	TimeoutMS  *int    `json:"timeout_ms"`
	RetryCodes *[]int  `json:"retry_codes"`
}

func RemapRuleToToJSON

func RemapRuleToToJSON(r remapdata.RemapRuleTo) RemapRuleToJSON

type RemapRules

type RemapRules struct {
	RemapRulesBase
	Rules           []remapdata.RemapRule
	RetryCodes      map[int]struct{}
	Timeout         *time.Duration
	ParentSelection *remapdata.ParentSelectionType
	Stats           remapdata.RemapRulesStats
	Plugins         map[string]interface{}
	Cache           icache.Cache
}

type RemapRulesBase

type RemapRulesBase struct {
	RetryNum      *int                       `json:"retry_num"`
	PluginsShared map[string]json.RawMessage `json:"plugins_shared"`
}

type RemapRulesJSON

type RemapRulesJSON struct {
	RemapRulesBase
	Rules           []RemapRuleJSON            `json:"rules"`
	RetryCodes      *[]int                     `json:"retry_codes"`
	TimeoutMS       *int                       `json:"timeout_ms"`
	ParentSelection *string                    `json:"parent_selection"`
	Stats           RemapRulesStatsJSON        `json:"stats"`
	Plugins         map[string]json.RawMessage `json:"plugins"`
}

func RemapRulesToJSON

func RemapRulesToJSON(r RemapRules) (RemapRulesJSON, error)

type RemapRulesStatsJSON

type RemapRulesStatsJSON struct {
	Allow []string `json:"allow"`
	Deny  []string `json:"deny"`
}

type Remapper

type Remapper interface {
	// Remap returns the given string remapped, the unique name of the rule found, and whether a remap rule was found
	Remap(uri string) (remapdata.RemapRule, bool)
	// Rules returns the unique names of every remap rule.
	Rules() []remapdata.RemapRule
	// PluginCfg returns the global plugins, outside the individual remap rules
	PluginCfg() map[string]interface{}
	PluginSharedCfg() map[string]map[string]json.RawMessage
}

Remapper provides a function which takes strings and maps them to other strings. This is designed for URL prefix remapping, for a reverse proxy.

func NewLiteralPrefixRemapper

func NewLiteralPrefixRemapper(remap []remapdata.RemapRule, plugins map[string]interface{}) Remapper

type Remapping

type Remapping struct {
	Request         *http.Request
	ProxyURL        *url.URL
	Name            string
	CacheKey        string
	ConnectionClose bool
	Timeout         time.Duration
	RetryNum        int
	RetryCodes      map[int]struct{}
	Cache           icache.Cache
	Transport       *http.Transport
}

type RemappingProducer

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

RemappingProducer takes an HTTP Request and returns a Remapping to be used for that request. TODO rename? interface?

func (*RemappingProducer) Cache

func (p *RemappingProducer) Cache() icache.Cache

func (*RemappingProducer) CacheKey

func (p *RemappingProducer) CacheKey() string

func (*RemappingProducer) ConnectionClose

func (p *RemappingProducer) ConnectionClose() bool

func (*RemappingProducer) DSCP

func (p *RemappingProducer) DSCP() int

func (*RemappingProducer) FirstFQDN

func (p *RemappingProducer) FirstFQDN() string

func (*RemappingProducer) GetNext

func (p *RemappingProducer) GetNext(r *http.Request) (Remapping, bool, error)

GetNext returns the remapping to use to request, whether retries are allowed (i.e. if this is the last retry), or any error

func (*RemappingProducer) Name

func (p *RemappingProducer) Name() string

func (*RemappingProducer) OverrideCacheKey

func (p *RemappingProducer) OverrideCacheKey(newKey string)

func (*RemappingProducer) PluginCfg

func (p *RemappingProducer) PluginCfg() map[string]interface{}

func (*RemappingProducer) ProxyStr

func (p *RemappingProducer) ProxyStr() string

Jump to

Keyboard shortcuts

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