Documentation ¶
Overview ¶
Package httpproxy provides the Proxy of HTTP.
Index ¶
- Constants
- func HTTPClient(tlsCfg *tls.Config, spec *HTTPClientSpec, timeout time.Duration) *http.Client
- func NewHTTPHealthChecker(tlsConfig *tls.Config, spec *ProxyHealthCheckSpec) proxies.HealthChecker
- func NewRequestMatcher(spec *RequestMatcherSpec) proxies.RequestMatcher
- func NewWebSocketHealthChecker(spec *WSProxyHealthCheckSpec) proxies.HealthChecker
- type BaseServerPool
- type BaseServerPoolSpec
- type CacheEntry
- type CompressionSpec
- type HTTPClientSpec
- type HTTPHealthCheckSpec
- type HealthCheckBodyMatch
- type HealthCheckHeaderMatch
- type HealthCheckMatch
- type LoadBalanceSpec
- type LoadBalancer
- type MTLS
- type MemoryCache
- type MemoryCacheSpec
- type MethodAndURLMatcher
- type Proxy
- func (p *Proxy) Close()
- func (p *Proxy) Handle(ctx *context.Context) (result string)
- func (p *Proxy) Inherit(previousGeneration filters.Filter)
- func (p *Proxy) Init()
- func (p *Proxy) InjectResiliencePolicy(policies map[string]resilience.Policy)
- func (p *Proxy) Kind() *filters.Kind
- func (p *Proxy) Name() string
- func (p *Proxy) Spec() filters.Spec
- func (p *Proxy) Status() interface{}
- type ProxyHealthCheckSpec
- type RequestMatcher
- type RequestMatcherSpec
- type Server
- type ServerPool
- type ServerPoolSpec
- type ServerPoolStatus
- type SimpleHTTPProxy
- func (shp *SimpleHTTPProxy) Close()
- func (shp *SimpleHTTPProxy) Handle(ctx *context.Context) (result string)
- func (shp *SimpleHTTPProxy) Inherit(previousGeneration filters.Filter)
- func (shp *SimpleHTTPProxy) Init()
- func (shp *SimpleHTTPProxy) InjectResiliencePolicy(policies map[string]resilience.Policy)
- func (shp *SimpleHTTPProxy) Kind() *filters.Kind
- func (shp *SimpleHTTPProxy) Name() string
- func (shp *SimpleHTTPProxy) Spec() filters.Spec
- func (shp *SimpleHTTPProxy) Status() interface{}
- type SimpleHTTPProxySpec
- type Spec
- type Status
- type WSHealthCheckSpec
- type WSProxyHealthCheckSpec
- type WebSocketProxy
- func (p *WebSocketProxy) Close()
- func (p *WebSocketProxy) Handle(ctx *context.Context) (result string)
- func (p *WebSocketProxy) Inherit(previousGeneration filters.Filter)
- func (p *WebSocketProxy) Init()
- func (p *WebSocketProxy) Kind() *filters.Kind
- func (p *WebSocketProxy) Name() string
- func (p *WebSocketProxy) Spec() filters.Spec
- func (p *WebSocketProxy) Status() interface{}
- type WebSocketProxySpec
- type WebSocketServerPool
- type WebSocketServerPoolSpec
Constants ¶
const (
// Kind is the kind of Proxy.
Kind = "Proxy"
)
const WebSocketProxyKind = "WebSocketProxy"
WebSocketProxyKind is the kind of WebSocketProxy.
Variables ¶
This section is empty.
Functions ¶
func HTTPClient ¶
func NewHTTPHealthChecker ¶ added in v2.6.4
func NewHTTPHealthChecker(tlsConfig *tls.Config, spec *ProxyHealthCheckSpec) proxies.HealthChecker
NewHTTPHealthChecker creates a new HTTP health checker.
func NewRequestMatcher ¶
func NewRequestMatcher(spec *RequestMatcherSpec) proxies.RequestMatcher
NewRequestMatcher creates a new traffic matcher according to spec.
func NewWebSocketHealthChecker ¶ added in v2.6.4
func NewWebSocketHealthChecker(spec *WSProxyHealthCheckSpec) proxies.HealthChecker
Types ¶
type BaseServerPool ¶
type BaseServerPool = proxies.ServerPoolBase
BaseServerPool is the base of a server pool.
type BaseServerPoolSpec ¶
type BaseServerPoolSpec = proxies.ServerPoolBaseSpec
BaseServerPoolSpec is the spec of BaseServerPool.
type CacheEntry ¶
CacheEntry is an item of the memory cache.
type CompressionSpec ¶
type CompressionSpec struct {
MinLength uint32 `json:"minLength"`
}
CompressionSpec describes the compression.
type HTTPClientSpec ¶ added in v2.5.3
HTTPClientSpec is the spec of HTTPClient.
type HTTPHealthCheckSpec ¶ added in v2.6.4
type HTTPHealthCheckSpec struct { Port int `json:"port,omitempty"` URI string `json:"uri,omitempty"` Method string `json:"method,omitempty"` Headers map[string]string `json:"headers,omitempty"` Body string `json:"body,omitempty"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` Match *HealthCheckMatch `json:"match,omitempty"` }
HTTPHealthCheckSpec is the spec of HTTP health check.
func (*HTTPHealthCheckSpec) Validate ¶ added in v2.6.4
func (spec *HTTPHealthCheckSpec) Validate() error
Validate validates HTTPHealthCheckSpec.
type HealthCheckBodyMatch ¶ added in v2.6.4
type HealthCheckBodyMatch struct { Value string `json:"value,omitempty"` // Type is the match type, contains or regex Type string `json:"type,omitempty"` // contains filtered or unexported fields }
HealthCheckBodyMatch is the match spec of health check body.
type HealthCheckHeaderMatch ¶ added in v2.6.4
type HealthCheckHeaderMatch struct { Name string `json:"name,omitempty"` Value string `json:"value,omitempty"` // Type is the match type, exact or regex Type string `json:"type,omitempty"` // contains filtered or unexported fields }
HealthCheckHeaderMatch is the match spec of health check header.
type HealthCheckMatch ¶ added in v2.6.4
type HealthCheckMatch struct { StatusCodes [][]int `json:"statusCodes,omitempty"` Headers []HealthCheckHeaderMatch `json:"headers,omitempty"` Body *HealthCheckBodyMatch `json:"body,omitempty"` }
HealthCheckMatch is the match spec of health check.
func (*HealthCheckMatch) Match ¶ added in v2.6.4
func (match *HealthCheckMatch) Match(resp *http.Response) error
func (*HealthCheckMatch) Validate ¶ added in v2.6.4
func (match *HealthCheckMatch) Validate() error
type LoadBalanceSpec ¶
type LoadBalanceSpec = proxies.LoadBalanceSpec
LoadBalanceSpec is the spec of a load balancer.
type LoadBalancer ¶
type LoadBalancer = proxies.LoadBalancer
LoadBalancer is the interface of a load balancer.
type MTLS ¶
type MTLS struct { CertBase64 string `json:"certBase64" jsonschema:"required,format=base64"` KeyBase64 string `json:"keyBase64" jsonschema:"required,format=base64"` RootCertBase64 string `json:"rootCertBase64" jsonschema:"required,format=base64"` InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"` }
MTLS is the configuration for client side mTLS.
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is an utility MemoryCache.
func NewMemoryCache ¶
func NewMemoryCache(spec *MemoryCacheSpec) *MemoryCache
NewMemoryCache creates a MemoryCache.
func (*MemoryCache) Load ¶
func (mc *MemoryCache) Load(req *httpprot.Request) *CacheEntry
Load tries to load cache for HTTPContext.
type MemoryCacheSpec ¶
type MemoryCacheSpec struct { Expiration string `json:"expiration" jsonschema:"required,format=duration"` MaxEntryBytes uint32 `json:"maxEntryBytes" jsonschema:"required,minimum=1"` Codes []int `json:"codes" jsonschema:"required,minItems=1,uniqueItems=true,format=httpcode-array"` Methods []string `json:"methods" jsonschema:"required,minItems=1,uniqueItems=true,format=httpmethod-array"` }
MemoryCacheSpec describes the MemoryCache.
type MethodAndURLMatcher ¶
type MethodAndURLMatcher struct { Methods []string `json:"methods,omitempty" jsonschema:"uniqueItems=true,format=httpmethod-array"` URL *stringtool.StringMatcher `json:"url" jsonschema:"required"` }
MethodAndURLMatcher defines the match rule of a http request
func (*MethodAndURLMatcher) Match ¶
func (r *MethodAndURLMatcher) Match(req *httpprot.Request) bool
Match matches a request.
func (*MethodAndURLMatcher) Validate ¶
func (r *MethodAndURLMatcher) Validate() error
Validate validates the MethodAndURLMatcher.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is the filter Proxy.
func (*Proxy) InjectResiliencePolicy ¶
func (p *Proxy) InjectResiliencePolicy(policies map[string]resilience.Policy)
InjectResiliencePolicy injects resilience policies to the proxy.
type ProxyHealthCheckSpec ¶ added in v2.6.4
type ProxyHealthCheckSpec struct { proxies.HealthCheckSpec `json:",inline"` HTTPHealthCheckSpec `json:",inline"` }
ProxyHealthCheckSpec is the spec of http proxy health check.
func (*ProxyHealthCheckSpec) Validate ¶ added in v2.6.4
func (spec *ProxyHealthCheckSpec) Validate() error
Validate validates HealthCheckSpec.
type RequestMatcher ¶
type RequestMatcher = proxies.RequestMatcher
RequestMatcher is the interface of a request matcher
type RequestMatcherSpec ¶
type RequestMatcherSpec struct { proxies.RequestMatcherBaseSpec `json:",inline"` URLs []*MethodAndURLMatcher `json:"urls,omitempty"` }
RequestMatcherSpec describe RequestMatcher
func (*RequestMatcherSpec) Validate ¶
func (s *RequestMatcherSpec) Validate() error
Validate validates the RequestMatcherSpec.
type ServerPool ¶
type ServerPool struct { BaseServerPool // contains filtered or unexported fields }
ServerPool defines a server pool.
func NewServerPool ¶
func NewServerPool(proxy *Proxy, spec *ServerPoolSpec, name string) *ServerPool
NewServerPool creates a new server pool according to spec.
func (*ServerPool) CreateLoadBalancer ¶
func (sp *ServerPool) CreateLoadBalancer(spec *LoadBalanceSpec, servers []*Server) LoadBalancer
CreateLoadBalancer creates a load balancer according to spec.
func (*ServerPool) InjectResiliencePolicy ¶
func (sp *ServerPool) InjectResiliencePolicy(policies map[string]resilience.Policy)
InjectResiliencePolicy injects resilience policies to the server pool.
type ServerPoolSpec ¶
type ServerPoolSpec struct { BaseServerPoolSpec `json:",inline"` Filter *RequestMatcherSpec `json:"filter,omitempty"` SpanName string `json:"spanName,omitempty"` ServerMaxBodySize int64 `json:"serverMaxBodySize,omitempty"` Timeout string `json:"timeout,omitempty" jsonschema:"format=duration"` RetryPolicy string `json:"retryPolicy,omitempty"` CircuitBreakerPolicy string `json:"circuitBreakerPolicy,omitempty"` MemoryCache *MemoryCacheSpec `json:"memoryCache,omitempty"` HealthCheck *ProxyHealthCheckSpec `json:"healthCheck,omitempty"` // FailureCodes would be 5xx if it isn't assigned any value. FailureCodes []int `json:"failureCodes,omitempty" jsonschema:"uniqueItems=true"` }
ServerPoolSpec is the spec for a server pool.
func (*ServerPoolSpec) Validate ¶ added in v2.6.4
func (spec *ServerPoolSpec) Validate() error
type ServerPoolStatus ¶
ServerPoolStatus is the status of Pool.
type SimpleHTTPProxy ¶
type SimpleHTTPProxy struct {
// contains filtered or unexported fields
}
SimpleHTTPProxy is the filter SimpleHTTPProxy.
func (*SimpleHTTPProxy) Handle ¶
func (shp *SimpleHTTPProxy) Handle(ctx *context.Context) (result string)
Handle handles HTTPContext.
func (*SimpleHTTPProxy) Inherit ¶
func (shp *SimpleHTTPProxy) Inherit(previousGeneration filters.Filter)
Inherit inherits previous generation of SimpleHTTPProxy.
func (*SimpleHTTPProxy) InjectResiliencePolicy ¶
func (shp *SimpleHTTPProxy) InjectResiliencePolicy(policies map[string]resilience.Policy)
func (*SimpleHTTPProxy) Kind ¶
func (shp *SimpleHTTPProxy) Kind() *filters.Kind
Kind returns the kind of SimpleHTTPProxy.
func (*SimpleHTTPProxy) Name ¶
func (shp *SimpleHTTPProxy) Name() string
Name returns the name of the SimpleHTTPProxySpec filter instance.
func (*SimpleHTTPProxy) Spec ¶
func (shp *SimpleHTTPProxy) Spec() filters.Spec
Spec returns the spec used by the SimpleHTTPProxy.
func (*SimpleHTTPProxy) Status ¶
func (shp *SimpleHTTPProxy) Status() interface{}
Status returns SimpleHTTPProxy status.
type SimpleHTTPProxySpec ¶
type SimpleHTTPProxySpec struct { filters.BaseSpec `json:",inline"` Compression *CompressionSpec `json:"compression,omitempty"` MaxIdleConns int `json:"maxIdleConns,omitempty"` MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost,omitempty"` ServerMaxBodySize int64 `json:"serverMaxBodySize,omitempty"` Timeout string `json:"timeout,omitempty" jsonschema:"format=duration"` RetryPolicy string `json:"retryPolicy,omitempty"` }
SimpleHTTPProxySpec describes the SimpleHTTPProxy.
func (*SimpleHTTPProxySpec) Validate ¶
func (s *SimpleHTTPProxySpec) Validate() error
Validate validates SimpleHTTPProxySpec.
type Spec ¶
type Spec struct { filters.BaseSpec `json:",inline"` Pools []*ServerPoolSpec `json:"pools" jsonschema:"required"` MirrorPool *ServerPoolSpec `json:"mirrorPool,omitempty"` Compression *CompressionSpec `json:"compression,omitempty"` MTLS *MTLS `json:"mtls,omitempty"` MaxIdleConns int `json:"maxIdleConns,omitempty"` MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost,omitempty"` MaxRedirection int `json:"maxRedirection,omitempty"` ServerMaxBodySize int64 `json:"serverMaxBodySize,omitempty"` }
Spec describes the Proxy.
type Status ¶
type Status struct { MainPool *ServerPoolStatus `json:"mainPool"` CandidatePools []*ServerPoolStatus `json:"candidatePools,omitempty"` MirrorPool *ServerPoolStatus `json:"mirrorPool,omitempty"` }
Status is the status of Proxy.
type WSHealthCheckSpec ¶ added in v2.6.4
type WSHealthCheckSpec struct { Port int `json:"port,omitempty"` URI string `json:"uri,omitempty"` Headers map[string]string `json:"headers,omitempty"` Match *HealthCheckMatch `json:"match,omitempty"` }
type WSProxyHealthCheckSpec ¶ added in v2.6.4
type WSProxyHealthCheckSpec struct { proxies.HealthCheckSpec `json:",inline"` HTTP *HTTPHealthCheckSpec `json:"http,omitempty"` WS *WSHealthCheckSpec `json:"ws,omitempty"` }
WSProxyHealthCheckSpec is the spec of ws proxy health check.
func (*WSProxyHealthCheckSpec) Validate ¶ added in v2.6.4
func (spec *WSProxyHealthCheckSpec) Validate() error
type WebSocketProxy ¶
type WebSocketProxy struct {
// contains filtered or unexported fields
}
WebSocketProxy is the filter WebSocketProxy.
TODO: it is better to put filters to their own folders, so we need a refactor to extract the WebSocketProxy into its own folder later.
func (*WebSocketProxy) Handle ¶
func (p *WebSocketProxy) Handle(ctx *context.Context) (result string)
Handle handles HTTPContext.
func (*WebSocketProxy) Inherit ¶
func (p *WebSocketProxy) Inherit(previousGeneration filters.Filter)
Inherit inherits previous generation of WebSocketProxy.
func (*WebSocketProxy) Kind ¶
func (p *WebSocketProxy) Kind() *filters.Kind
Kind returns the kind of WebSocketProxy.
func (*WebSocketProxy) Name ¶
func (p *WebSocketProxy) Name() string
Name returns the name of the WebSocketProxy filter instance.
func (*WebSocketProxy) Spec ¶
func (p *WebSocketProxy) Spec() filters.Spec
Spec returns the spec used by the WebSocketProxy
func (*WebSocketProxy) Status ¶
func (p *WebSocketProxy) Status() interface{}
Status returns WebSocketProxy status.
type WebSocketProxySpec ¶
type WebSocketProxySpec struct { filters.BaseSpec `json:",inline"` Pools []*WebSocketServerPoolSpec `json:"pools" jsonschema:"required"` }
WebSocketProxySpec describes the WebSocketProxy.
func (*WebSocketProxySpec) Validate ¶
func (s *WebSocketProxySpec) Validate() error
Validate validates Spec.
type WebSocketServerPool ¶
type WebSocketServerPool struct { BaseServerPool // contains filtered or unexported fields }
WebSocketServerPool defines a server pool.
func NewWebSocketServerPool ¶
func NewWebSocketServerPool(proxy *WebSocketProxy, spec *WebSocketServerPoolSpec, name string) *WebSocketServerPool
NewWebSocketServerPool creates a new server pool according to spec.
func (*WebSocketServerPool) CreateLoadBalancer ¶
func (sp *WebSocketServerPool) CreateLoadBalancer(spec *LoadBalanceSpec, servers []*Server) LoadBalancer
CreateLoadBalancer creates a load balancer according to spec.
type WebSocketServerPoolSpec ¶
type WebSocketServerPoolSpec struct { BaseServerPoolSpec `json:",inline"` ClientMaxMsgSize int64 `json:"clientMaxMsgSize,omitempty"` ServerMaxMsgSize int64 `json:"serverMaxMsgSize,omitempty"` Filter *RequestMatcherSpec `json:"filter,omitempty"` InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"` OriginPatterns []string `json:"originPatterns,omitempty"` HealthCheck *WSProxyHealthCheckSpec `json:"healthCheck,omitempty"` }
WebSocketServerPoolSpec is the spec for a server pool.