vhost

package
v0.52.5 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotFound = `` /* 487-byte string literal not displayed */

)

Variables

View Source
var ErrNoRouteFound = errors.New("no route found")
View Source
var ErrRouterConfigConflict = errors.New("router config conflict")
View Source
var NotFoundPagePath = ""

Functions

func GetHTTPSHostname

func GetHTTPSHostname(c net.Conn) (_ net.Conn, _ map[string]string, err error)

func NotFoundResponse

func NotFoundResponse() *http.Response

Types

type ByLocation

type ByLocation []*Router

sort by location

func (ByLocation) Len

func (a ByLocation) Len() int

func (ByLocation) Less

func (a ByLocation) Less(i, j int) bool

func (ByLocation) Swap

func (a ByLocation) Swap(i, j int)

type ChooseEndpointFunc

type ChooseEndpointFunc func() (string, error)

type CreateConnByEndpointFunc

type CreateConnByEndpointFunc func(endpoint, remoteAddr string) (net.Conn, error)

type CreateConnFunc

type CreateConnFunc func(remoteAddr string) (net.Conn, error)

type HTTPReverseProxy

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

func NewHTTPReverseProxy

func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *HTTPReverseProxy

func (*HTTPReverseProxy) CheckAuth

func (rp *HTTPReverseProxy) CheckAuth(domain, location, routeByHTTPUser, user, passwd string) bool

func (*HTTPReverseProxy) CreateConnection

func (rp *HTTPReverseProxy) CreateConnection(reqRouteInfo *RequestRouteInfo, byEndpoint bool) (net.Conn, error)

CreateConnection create a new connection by route config

func (*HTTPReverseProxy) GetHeaders

func (rp *HTTPReverseProxy) GetHeaders(domain, location, routeByHTTPUser string) (headers map[string]string)

func (*HTTPReverseProxy) GetRouteConfig

func (rp *HTTPReverseProxy) GetRouteConfig(domain, location, routeByHTTPUser string) *RouteConfig

func (*HTTPReverseProxy) Register

func (rp *HTTPReverseProxy) Register(routeCfg RouteConfig) error

Register register the route config to reverse proxy reverse proxy will use CreateConnFn from routeCfg to create a connection to the remote service

func (*HTTPReverseProxy) ServeHTTP

func (rp *HTTPReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*HTTPReverseProxy) UnRegister

func (rp *HTTPReverseProxy) UnRegister(routeCfg RouteConfig)

UnRegister unregister route config by domain and location

type HTTPReverseProxyOptions

type HTTPReverseProxyOptions struct {
	ResponseHeaderTimeoutS int64
}

type HTTPSMuxer

type HTTPSMuxer struct {
	*Muxer
}

func NewHTTPSMuxer

func NewHTTPSMuxer(listener net.Listener, timeout time.Duration) (*HTTPSMuxer, error)

type Listener

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

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

func (*Listener) Close

func (l *Listener) Close() error

func (*Listener) Name

func (l *Listener) Name() string

type Muxer

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

Muxer is a functional component used for https and tcpmux proxies. It accepts connections and extracts vhost information from the beginning of the connection data. It then routes the connection to its appropriate listener.

func NewMuxer

func NewMuxer(
	listener net.Listener,
	vhostFunc muxFunc,
	timeout time.Duration,
) (mux *Muxer, err error)

func (*Muxer) Listen

func (v *Muxer) Listen(ctx context.Context, cfg *RouteConfig) (l *Listener, err error)

listen for a new domain name, if rewriteHost is not empty and rewriteHost func is not nil, then rewrite the host header to rewriteHost

func (*Muxer) SetCheckAuthFunc

func (v *Muxer) SetCheckAuthFunc(f authFunc) *Muxer

func (*Muxer) SetFailHookFunc

func (v *Muxer) SetFailHookFunc(f failHookFunc) *Muxer

func (*Muxer) SetRewriteHostFunc

func (v *Muxer) SetRewriteHostFunc(f hostRewriteFunc) *Muxer

func (*Muxer) SetSuccessHookFunc

func (v *Muxer) SetSuccessHookFunc(f successHookFunc) *Muxer

type RequestRouteInfo

type RequestRouteInfo struct {
	URL        string
	Host       string
	HTTPUser   string
	RemoteAddr string
	URLHost    string
	Endpoint   string
}

type RouteConfig

type RouteConfig struct {
	Domain          string
	Location        string
	RewriteHost     string
	Username        string
	Password        string
	Headers         map[string]string
	RouteByHTTPUser string

	CreateConnFn           CreateConnFunc
	ChooseEndpointFn       ChooseEndpointFunc
	CreateConnByEndpointFn CreateConnByEndpointFunc
}

RouteConfig is the params used to match HTTP requests

type RouteInfo

type RouteInfo string
const (
	RouteInfoKey RouteInfo = "routeInfo"
)

type Router

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

type Routers

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

func NewRouters

func NewRouters() *Routers

func (*Routers) Add

func (r *Routers) Add(domain, location, httpUser string, payload interface{}) error

func (*Routers) Del

func (r *Routers) Del(domain, location, httpUser string)

func (*Routers) Get

func (r *Routers) Get(host, path, httpUser string) (vr *Router, exist bool)

Jump to

Keyboard shortcuts

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