proxy

package
Version: v0.0.0-...-91b31b5 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// YES when yes simply isn't enough
	YES = "yes"
	// HTTP string
	HTTP = "http"
	// HTTPS string
	HTTPS = "https"
)

Variables

View Source
var (
	// SERVERCOOKIE is the cookie string set by servers to set cookies on client
	SERVERCOOKIE = "Set-Cookie"
	// CLIENTCOOKIE is the cookie string set by clients to send cookies to the server
	CLIENTCOOKIE = "Cookie"
)

Functions

func BackendNodeStats

func BackendNodeStats(n []*BackendNode) []balancer.Statistics

BackendNodeStats gets statistics for backend nodes

Types

type ACL

type ACL struct {
	Action         string   `json:"action" toml:"action"`                   // remove, replace, add, deny
	HeaderKey      string   `json:"header_key" toml:"header_key"`           // header key
	HeaderValue    string   `json:"header_value" toml:"header_value"`       // header value
	CookieKey      string   `json:"cookie_key" toml:"cookie_key"`           // cookie key
	CookieValue    string   `json:"cookie_value" toml:"cookie_value"`       // cookie value
	CookiePath     string   `json:"cookie_path" toml:"cookie_path"`         // cookie path
	CookieExpire   duration `json:"cookie_expire" toml:"cookie_expire"`     // cookie expiry date
	CookieSecure   *bool    `json:"cookie_secure" toml:"cookie_secure"`     // cookie secure
	Cookiehttponly *bool    `json:"cookie_httponly" toml:"cookie_httponly"` // cookie httponly
	ConditionType  string   `json:"conditiontype" toml:"conditiontype"`     // header, cookie, other?
	ConditionMatch string   `json:"conditionmatch" toml:"conditionmatch"`   // header text (e.g. /^Content-Type: (.*)/(.*)$/i)
	URLMatch       string   `json:"urlmatch" toml:"urlmatch"`               // url match #^/(.*)#
	URLRewrite     string   `json:"urlrewrite" toml:"urlrewrite"`           // url rewrite /Other/Path/$1
	StatusCode     int      `json:"status_code" toml:"status_code"`         // status code
	URLPath        string   `json:"url_path" toml:"url_path"`               // request path to match this acl if provided
	CIDRS          []string `json:"cidrs" toml:"cidrs"`                     // network cidr
}

ACL is used by HTTP proxies for setting/removing headers, cookies or status code

func (ACL) ProcessRequest

func (acl ACL) ProcessRequest(req *http.Request) (deny bool)

ProcessRequest processes ACL's for request

func (ACL) ProcessResponse

func (acl ACL) ProcessResponse(res *http.Response) (deny bool)

ProcessResponse processes ACL's for response

func (ACL) ProcessTCPRequest

func (acl ACL) ProcessTCPRequest(clientIP string) (deny bool)

ProcessTCPRequest processes ACL's for tcp proxy

func (ACL) String

func (acl ACL) String() string

type ACLS

type ACLS []ACL

ACLS contains a list of ACL

func (ACLS) CountActions

func (acls ACLS) CountActions(action string) (count int)

CountActions returns the number of matches of action are in the ACL's

type Backend

type Backend struct {
	UUID            string
	BalanceMode     string
	ConnectMode     string
	InboundACL      ACLS
	OutboundACL     ACLS
	PreInboundRule  []string
	InboundRule     []string
	OutboundRule    []string
	Statistics      *balancer.Statistics
	Nodes           []*BackendNode
	Hostname        []string
	Fallback        string
	Uptime          time.Time
	ErrorPage       ErrorPage
	MaintenancePage ErrorPage
	// contains filtered or unexported fields
}

Backend is a backend where the proxy can connect to

func NewBackend

func NewBackend(uuid string, balancemode string, connectmode string, hostname []string, maxconnections int, errorPage ErrorPage, maintenancePage ErrorPage) *Backend

NewBackend creates a new backend

func (*Backend) AddBackendNode

func (b *Backend) AddBackendNode(n *BackendNode)

AddBackendNode adds a backend to the listener

func (*Backend) ClearStats

func (b *Backend) ClearStats()

ClearStats clears the statistics of all nodes of a backend

func (*Backend) GetBackend

func (b *Backend) GetBackend() (*BackendNode, error)

GetBackend Return the first backend

func (*Backend) GetBackendNodeBalanced

func (b *Backend) GetBackendNodeBalanced(backendpool, ip, sticky, balancemode string) (*BackendNode, healthcheck.Status, error)

GetBackendNodeBalanced returns a single backend node, based on balancer proto

func (*Backend) GetBackendNodeByID

func (b *Backend) GetBackendNodeByID(uuid string) (*BackendNode, error)

GetBackendNodeByID Return backend node by ID

func (*Backend) GetBackendsUUID

func (b *Backend) GetBackendsUUID() (n []string, err error)

GetBackendsUUID Return backend node by ID

func (*Backend) LoadErrorPage

func (b *Backend) LoadErrorPage(e ErrorPage) error

LoadErrorPage preloads the error page

func (*Backend) RemoveBackendNode

func (b *Backend) RemoveBackendNode(nodeid int)

RemoveBackendNode remove a backend node from the listener

func (*Backend) RemoveNodeByID

func (b *Backend) RemoveNodeByID(uuid string) error

RemoveNodeByID remove backend node by ID

func (*Backend) SetACL

func (b *Backend) SetACL(direction string, acl []ACL)

SetACL adds ACLs to the backend

func (*Backend) SetRules

func (b *Backend) SetRules(direction string, rule []string)

SetRules adds Rules to the backend

func (*Backend) UpdateBackendNode

func (b *Backend) UpdateBackendNode(nodeid int, status healthcheck.Status)

UpdateBackendNode update a backend node with a new status

type BackendNode

type BackendNode struct {
	UUID           string
	IP             string
	Hostname       string
	Port           int
	Statistics     *balancer.Statistics
	Uptime         time.Time
	MaxConnections int
	Preference     int
	Weight         int
	Status         healthcheck.Status
	LocalTopology  string   `json:"local_topology" toml:"local_topology"` // overrides localnetwork
	LocalNetwork   []string `json:"local_network" toml:"local_network"`   // used for topology based loadbalancing

}

BackendNode is a backendnode where the proxy can connect to

func NewBackendNode

func NewBackendNode(UUID string, IP string, hostname string, port int, maxconnections int, topology []string, preference int, weight int, status healthcheck.Status) *BackendNode

NewBackendNode creates a new node for a proxy backend

func (*BackendNode) Name

func (a *BackendNode) Name() string

Name returns the node name, either hostname or ip

type ErrorPage

type ErrorPage struct {
	File             string `json:"file" toml:"file"`                           // alternative error page to show
	StatusCode       int    `json:"statuscode" toml:"statuscode"`               // error code to give
	StatusMessage    string `json:"statusmessage" toml:"statusmessage"`         // error message to apply
	TriggerThreshold int    `json:"trigger_threshold" toml:"trigger_threshold"` // Theshold at which to trigger the error page (generally 500 and up)
	// contains filtered or unexported fields
}

ErrorPage contains the page to show on errors

type Listener

type Listener struct {
	UUID           string
	Name           string
	SourceIP       string
	IP             string
	Port           int
	ListenerMode   string // Protocol the listener expects
	HTTPProto      int    // HTTP Version Protocol the listener expects
	Backends       map[string]*Backend
	TLSConfig      *tls.Config // TLS Config
	MaxConnections int

	Statistics *balancer.Statistics

	ErrorPage       ErrorPage
	MaintenancePage ErrorPage
	ReadTimeout     int // Timeout in seconds to wait for the client sending the request - https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
	WriteTimeout    int // Timeout in seconds to wait for server reply to client
	Uptime          time.Time
	OCSPStapling    string // use OCSP Stapling
	// contains filtered or unexported fields
}

Listener contains the config for the proxy listener

func New

func New(uuid string, name string, maxconnections int) *Listener

New creates a new proxy for using a listener

func (*Listener) AddBackend

func (l *Listener) AddBackend(uuid string, name string, balancemode string, connectmode string, hostname []string, maxconnections int, errorPage ErrorPage, maintenancePage ErrorPage)

AddBackend adds a backend to an existing proxy

func (*Listener) Debug

func (l *Listener) Debug()

Debug shows output for debugging

func (*Listener) FindAllHostNames

func (l *Listener) FindAllHostNames() []string

FindAllHostNames searches for matching backend by hostname requested

func (*Listener) FindBackendByHost

func (l *Listener) FindBackendByHost(req string) (string, *Backend)

FindBackendByHost searches for matching backend by hostname requested

func (*Listener) GetBackend

func (l *Listener) GetBackend() (*Backend, error)

GetBackend Return the first backend

func (*Listener) GetBackendStats

func (l *Listener) GetBackendStats(backendName string) *balancer.Statistics

GetBackendStats gets the combined statistics from all nodes of a backend

func (*Listener) Handler

func (l *Listener) Handler(client net.Conn)

Handler handles clients and connectors proxys

func (*Listener) LoadErrorPage

func (l *Listener) LoadErrorPage(e ErrorPage) error

LoadErrorPage preloads the error page

func (*Listener) LoadMaintenancePage

func (l *Listener) LoadMaintenancePage(e ErrorPage) error

LoadMaintenancePage preloads the error page

func (*Listener) NewHTTPProxy

func (l *Listener) NewHTTPProxy() *httputil.ReverseProxy

NewHTTPProxy Create a HTTP proxy

func (*Listener) NewTCPProxy

func (l *Listener) NewTCPProxy() (net.Listener, error)

NewTCPProxy creates a new TCP proxy

func (*Listener) ProcessInboundRules

func (l *Listener) ProcessInboundRules(rules []string, req *http.Request, res *http.Response) error

ProcessInboundRules runs the rules script, and modified the given request accordingly Inbound rules apply only on the initial request before passing it on to a backend res can be nil, we need to ensure its only filled if we did set a response on the inbound rule

func (*Listener) ProcessOutboundRules

func (l *Listener) ProcessOutboundRules(rules []string, req *http.Request, res *http.Response) error

ProcessOutboundRules runs the rules script, and modified the given request/response accordingly Outbound rules are applied when contacting the backend, or replying the response to a client res cannot be nil at this point

func (*Listener) ProcessPreInboundRules

func (l *Listener) ProcessPreInboundRules(rules []string, req *http.Request) error

ProcessPreInboundRules runs the rules script, and modified the given request accordingly PreInbound rules apply only on the initial request before selecting a backend

func (*Listener) RemoveBackend

func (l *Listener) RemoveBackend(name string)

RemoveBackend removes a backend from the listener

func (*Listener) SetListener

func (l *Listener) SetListener(mode string, sourceIP string, ip string, port int, maxConnections int, tlsConfig *tls.Config, readTimeout int, writeTimeout int, httpProto int, ocspStapling string)

SetListener sets all listener config for the proxy

func (*Listener) Start

func (l *Listener) Start()

Start the listener

func (*Listener) Stop

func (l *Listener) Stop()

Stop exits the proxy process for the listener

func (*Listener) TCPProxy

func (l *Listener) TCPProxy(n net.Listener)

TCPProxy starts accepting connections

func (*Listener) UpdateBackend

func (l *Listener) UpdateBackend(uuid string, name string, balancemode string, connectmode string, hostname []string, maxconnections int, errorPage ErrorPage, maintenancePage ErrorPage)

UpdateBackend adds a backend to an existing proxy, or updates an existing one

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL