proxy

package
v1.0.0-pre Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAgent = "go-puzzle/1.0"

	ParamHeader = "header"
	ParamBody   = "body"
	ParamPath   = "path"
	ParamQuery  = "query"

	HeaderCookie        = "Cookie"
	HeaderContentType   = "Content-Type"
	HeaderUserAgent     = "User-Agent"
	HeaderAuthorization = "Authorization"
	HeaderXForwardFor   = "X-Forward-For"
	HeaderXRequestId    = "X-Request-ID"

	BodyJson = "application/json"
)
View Source
const (
	DefaultDerect             = "127.0.0.1:80"
	DefaultTimeout            = 10 * time.Second
	DefaultMaxIdleConn        = 100
	DefaultMaxConnPerHost     = 20
	DefaultMaxIdleConnPerHost = 10
	DefaultMaxResHeaderSize   = 1 << 20

	SchemeHttp  = "http://"
	SchemeHttps = "https://"
)

Variables

View Source
var (
	ErrInvalidPattern = errors.New("invalid uri pattern")
	ErrUnmatchPath    = errors.New("no match path param")
	ErrProxyReq       = errors.New("empty proxy request")
	ErrMissingQuery   = errors.New("missing query param")
	ErrEmptyResponse  = errors.New("parse empty response")
	ErrContextKey     = errors.New("unmatched http proxy context key")
)

Functions

func UseHttpProxy

func UseHttpProxy(contextKey string) echo.MiddlewareFunc

Types

type HttpPeer

type HttpPeer struct {
	Direct   bool
	Path     string
	QuerySet []string
	// contains filtered or unexported fields
}

func (HttpPeer) Uri

func (hp HttpPeer) Uri() string

type HttpProxy

type HttpProxy interface {
	Proxy
	ContextKey() string
	GenRequest(c echo.Context, peer HttpPeer) error
	SetupProxy(c echo.Context)
	GoProxy() error
	GetParamSet() ParamSet
	GetRequest() *http.Request
	GetResponse() *http.Response
	OriginBody() ([]byte, error)
	Bind(s interface{}) error
	Transparent(c echo.Context, peer HttpPeer) ([]byte, error)
	TransparentWithJson(c echo.Context, peer HttpPeer, s interface{}) error
}

func GetHttpProxy

func GetHttpProxy(c echo.Context, contextKey string) (HttpProxy, error)

func NewHttpProxy

func NewHttpProxy(opts ...HttpProxyOption) HttpProxy

type HttpProxyOption

type HttpProxyOption func(p *httpProxy)

type HttpProxyOptioner

type HttpProxyOptioner struct{}

func (HttpProxyOptioner) WithAddr

func (o HttpProxyOptioner) WithAddr(direct, redirect string) HttpProxyOption

func (HttpProxyOptioner) WithKey

func (o HttpProxyOptioner) WithKey(contextKey string) HttpProxyOption

func (HttpProxyOptioner) WithLogger

func (o HttpProxyOptioner) WithLogger(logger echo.Logger) HttpProxyOption

func (HttpProxyOptioner) WithScheme

func (o HttpProxyOptioner) WithScheme(scheme string) HttpProxyOption

func (HttpProxyOptioner) WithTls

func (o HttpProxyOptioner) WithTls(enable bool) HttpProxyOption

type ParamSet

type ParamSet map[string][]param

Used to pass parameters

func (ParamSet) AddParam

func (ps ParamSet) AddParam(group string, k, v string)

func (ParamSet) SetParam

func (ps ParamSet) SetParam(group string, k, v string)

type Proxy

type Proxy interface {
	State() bool
	Scheme() string
	DirectAddr() string
	RedirectAddr() string
}

Jump to

Keyboard shortcuts

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