proxy

package
v3.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Next:           nil,
	ModifyRequest:  nil,
	ModifyResponse: nil,
	Timeout:        fasthttp.DefaultLBClientTimeout,
}

ConfigDefault is the default config

Functions

func Balancer

func Balancer(config Config) fiber.Handler

Balancer creates a load balancer among multiple upstream servers

func BalancerForward

func BalancerForward(servers []string, clients ...*fasthttp.Client) fiber.Handler

BalancerForward Forward performs the given http request with round robin algorithm to server and fills the given http response. This method will return an fiber.Handler

func Do

func Do(c fiber.Ctx, addr string, clients ...*fasthttp.Client) error

Do performs the given http request and fills the given http response. This method can be used within a fiber.Handler

func DoDeadline

func DoDeadline(c fiber.Ctx, addr string, deadline time.Time, clients ...*fasthttp.Client) error

DoDeadline performs the given request and waits for response until the given deadline. This method can be used within a fiber.Handler

func DoRedirects

func DoRedirects(c fiber.Ctx, addr string, maxRedirectsCount int, clients ...*fasthttp.Client) error

DoRedirects performs the given http request and fills the given http response, following up to maxRedirectsCount redirects. When the redirect count exceeds maxRedirectsCount, ErrTooManyRedirects is returned. This method can be used within a fiber.Handler

func DoTimeout

func DoTimeout(c fiber.Ctx, addr string, timeout time.Duration, clients ...*fasthttp.Client) error

DoTimeout performs the given request and waits for response during the given timeout duration. This method can be used within a fiber.Handler

func DomainForward

func DomainForward(hostname, addr string, clients ...*fasthttp.Client) fiber.Handler

DomainForward performs an http request based on the given domain and populates the given http response. This method will return an fiber.Handler

func Forward

func Forward(addr string, clients ...*fasthttp.Client) fiber.Handler

Forward performs the given http request and fills the given http response. This method will return an fiber.Handler

func WithClient

func WithClient(cli *fasthttp.Client)

WithClient sets the global proxy client. This function should be called before Do and Forward.

Types

type Config

type Config struct {
	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c fiber.Ctx) bool

	// Servers defines a list of <scheme>://<host> HTTP servers,
	//
	// which are used in a round-robin manner.
	// i.e.: "https://foobar.com, http://www.foobar.com"
	//
	// Required
	Servers []string

	// ModifyRequest allows you to alter the request
	//
	// Optional. Default: nil
	ModifyRequest fiber.Handler

	// ModifyResponse allows you to alter the response
	//
	// Optional. Default: nil
	ModifyResponse fiber.Handler

	// Timeout is the request timeout used when calling the proxy client
	//
	// Optional. Default: 1 second
	Timeout time.Duration

	// Per-connection buffer size for requests' reading.
	// This also limits the maximum header size.
	// Increase this buffer if your clients send multi-KB RequestURIs
	// and/or multi-KB headers (for example, BIG cookies).
	ReadBufferSize int

	// Per-connection buffer size for responses' writing.
	WriteBufferSize int

	// tls config for the http client.
	TlsConfig *tls.Config //nolint:stylecheck,revive // TODO: Rename to "TLSConfig" in v3

	// Client is custom client when client config is complex.
	// Note that Servers, Timeout, WriteBufferSize, ReadBufferSize, TlsConfig
	// and DialDualStack will not be used if the client are set.
	Client *fasthttp.LBClient

	// Attempt to connect to both ipv4 and ipv6 host addresses if set to true.
	//
	// By default client connects only to ipv4 addresses, since unfortunately ipv6
	// remains broken in many networks worldwide :)
	//
	// Optional. Default: false
	DialDualStack bool
}

Config defines the config for middleware.

Jump to

Keyboard shortcuts

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