proxy

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PolicyRoundRobin is the policy of round-robin.
	PolicyRoundRobin = "roundRobin"
	// PolicyRandom is the policy of random.
	PolicyRandom = "random"
	// PolicyWeightedRandom is the policy of weighted random.
	PolicyWeightedRandom = "weightedRandom"
	// PolicyIPHash is the policy of ip hash.
	PolicyIPHash = "ipHash"
	// PolicyHeaderHash is the policy of header hash.
	PolicyHeaderHash = "headerHash"
)
View Source
const (
	// Kind is the kind of Proxy.
	Kind = "Proxy"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v1.5.2

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

Client is a wrapper around http.Client.

func NewClient added in v1.5.2

func NewClient(cl *http.Client, tr *tracing.Tracing) *Client

NewClient creates a wrapper around http.Client

func (*Client) Do added in v1.5.2

func (c *Client) Do(r *http.Request) (*http.Response, error)

Do calls the correct http client

type CompressionSpec

type CompressionSpec struct {
	MinLength uint32 `yaml:"minLength"`
}

CompressionSpec describes the compression.

type FallbackSpec

type FallbackSpec struct {
	ForCodes      bool `yaml:"forCodes"`
	fallback.Spec `yaml:",inline"`
}

FallbackSpec describes the fallback policy.

type LoadBalance

type LoadBalance struct {
	Policy        string `yaml:"policy" jsonschema:"required,enum=roundRobin,enum=random,enum=weightedRandom,enum=ipHash,enum=headerHash"`
	HeaderHashKey string `yaml:"headerHashKey" jsonschema:"omitempty"`
}

LoadBalance is load balance for multiple servers.

func (LoadBalance) Validate

func (lb LoadBalance) Validate() error

Validate validates LoadBalance.

type MTLS added in v1.3.1

type MTLS struct {
	CertBase64     string `yaml:"certBase64" jsonschema:"required,format=base64"`
	KeyBase64      string `yaml:"keyBase64" jsonschema:"required,format=base64"`
	RootCertBase64 string `yaml:"rootCertBase64" jsonschema:"required,format=base64"`
}

MTLS is the configuration for client side mTLS.

type PoolSpec

type PoolSpec struct {
	SpanName        string            `yaml:"spanName" jsonschema:"omitempty"`
	Filter          *httpfilter.Spec  `yaml:"filter" jsonschema:"omitempty"`
	ServersTags     []string          `yaml:"serversTags" jsonschema:"omitempty,uniqueItems=true"`
	Servers         []*Server         `yaml:"servers" jsonschema:"omitempty"`
	ServiceRegistry string            `yaml:"serviceRegistry" jsonschema:"omitempty"`
	ServiceName     string            `yaml:"serviceName" jsonschema:"omitempty"`
	LoadBalance     *LoadBalance      `yaml:"loadBalance" jsonschema:"required"`
	MemoryCache     *memorycache.Spec `yaml:"memoryCache,omitempty" jsonschema:"omitempty"`
}

PoolSpec describes a pool of servers.

func (PoolSpec) Validate

func (s PoolSpec) Validate() error

Validate validates poolSpec.

type PoolStatus

type PoolStatus struct {
	Stat *httpstat.Status `yaml:"stat"`
}

PoolStatus is the status of Pool.

type Proxy

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

Proxy is the filter Proxy.

func (*Proxy) Close

func (b *Proxy) Close()

Close closes Proxy.

func (*Proxy) DefaultSpec

func (b *Proxy) DefaultSpec() interface{}

DefaultSpec returns the default spec of Proxy.

func (*Proxy) Description

func (b *Proxy) Description() string

Description returns the description of Proxy.

func (*Proxy) Handle

func (b *Proxy) Handle(ctx context.HTTPContext) (result string)

Handle handles HTTPContext. When we create new request for backend, we call http.NewRequestWithContext method and use context.Request().Body() as body. Based on golang std lib comments: https://github.com/golang/go/blob/95b68e1e02fa713719f02f6c59fb1532bd05e824/src/net/http/request.go#L856-L860 If body is of type *bytes.Buffer, *bytes.Reader, or *strings.Reader, the returned request's ContentLength is set to its exact value (instead of -1), GetBody is populated (so 307 and 308 redirects can replay the body), and Body is set to NoBody if the ContentLength is 0.

So in this way, http.Request.ContentLength will be 0, and when http.Client send this request, it will delete "Content-Length" key in header. We solve this problem by set http.Request.ContentLength equal to http.Request.Header["Content-Length"] (if it is presented). Reading all context.Request().Body() and create new request with bytes.NewReader is another way, but it may cause performance loss.

It is important that "Content-Length" in the Header is equal to the length of the Body. In easegress, when a filter change Request.Body, it will delete the header of "Content-Length". So, you should not worry about this when using our filters. But for customer filters, developer should make sure to delete or set "Context-Length" value in header when change Request.Body.

func (*Proxy) Inherit

func (b *Proxy) Inherit(filterSpec *httppipeline.FilterSpec, previousGeneration httppipeline.Filter)

Inherit inherits previous generation of Proxy.

func (*Proxy) Init

func (b *Proxy) Init(filterSpec *httppipeline.FilterSpec)

Init initializes Proxy.

func (*Proxy) Kind

func (b *Proxy) Kind() string

Kind returns the kind of Proxy.

func (*Proxy) Results

func (b *Proxy) Results() []string

Results returns the results of Proxy.

func (*Proxy) Status

func (b *Proxy) Status() interface{}

Status returns Proxy status.

type Server

type Server struct {
	URL      string   `yaml:"url" jsonschema:"required,format=url"`
	Tags     []string `yaml:"tags" jsonschema:"omitempty,uniqueItems=true"`
	Weight   int      `yaml:"weight" jsonschema:"omitempty,minimum=0,maximum=100"`
	KeepHost bool     `yaml:"keepHost" jsonschema:"omitempty,default=false`
	// contains filtered or unexported fields
}

Server is proxy server.

func (*Server) String

func (s *Server) String() string

String implements the Stringer interface.

type Spec

type Spec struct {
	Fallback            *FallbackSpec    `yaml:"fallback,omitempty" jsonschema:"omitempty"`
	MainPool            *PoolSpec        `yaml:"mainPool" jsonschema:"required"`
	CandidatePools      []*PoolSpec      `yaml:"candidatePools,omitempty" jsonschema:"omitempty"`
	MirrorPool          *PoolSpec        `yaml:"mirrorPool,omitempty" jsonschema:"omitempty"`
	FailureCodes        []int            `yaml:"failureCodes" jsonschema:"omitempty,uniqueItems=true,format=httpcode-array"`
	Compression         *CompressionSpec `yaml:"compression,omitempty" jsonschema:"omitempty"`
	MTLS                *MTLS            `yaml:"mtls,omitempty" jsonschema:"omitempty"`
	MaxIdleConns        int              `yaml:"maxIdleConns" jsonschema:"omitempty"`
	MaxIdleConnsPerHost int              `yaml:"maxIdleConnsPerHost" jsonschema:"omitempty"`
}

Spec describes the Proxy.

func (Spec) Validate

func (s Spec) Validate() error

Validate validates Spec.

type Status

type Status struct {
	MainPool       *PoolStatus   `yaml:"mainPool"`
	CandidatePools []*PoolStatus `yaml:"candidatePools,omitempty"`
	MirrorPool     *PoolStatus   `yaml:"mirrorPool,omitempty"`
}

Status is the status of Proxy.

Jump to

Keyboard shortcuts

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