Documentation
¶
Overview ¶
Package proxy implements the extensions to a SimpleServer necessary to implement a full HTTP(S) Reverse Proxy.
This package relies heavily on the "server" and "client" packages of this library to perform the actual routing and Request/Response Handling. The primary additional logic of this package is the "doReverseProxy" function, making use of a "ReverseProxyRouterFunc".
The high-level idea of how this package operates is that all incoming requests which the proxy server is configured to accept (URI's match the path prefix) will be processed by the given "ReverseProxyRouterFunc". This function must be able to look at the current request and determine the host to forward to from it. This function MUST return the new host to forward to. The proxy server then uses a SimpleClient to perform the request before writing the response back to the original request source.
Index ¶
- Variables
- func ConfigureReverseProxy(S *server.SimpleServer, Client *client.SimpleClient, logger *log.Logger, ...) *server.SimpleServer
- func DoReverseProxy(C *client.SimpleClient, Matcher ReverseProxyRouterFunc, logger *log.Logger) http.HandlerFunc
- func NotFoundHandlerProxyOverride(S *server.SimpleServer, c *client.SimpleClient, ...)
- type ReverseProxyRouterFunc
- type ReverseProxyRoutingRule
- type ReverseProxyRuleSet
Constants ¶
This section is empty.
Variables ¶
var ( ErrForbiddenRoute error = errors.New("easytls proxy error - Forbidden route") ErrRouteNotFound error = errors.New("easytls routing rule error - No forwarding rule defined for route") )
Define the set of errors provided by this package
Functions ¶
func ConfigureReverseProxy ¶
func ConfigureReverseProxy(S *server.SimpleServer, Client *client.SimpleClient, logger *log.Logger, RouteMatcher ReverseProxyRouterFunc, PathPrefix string) *server.SimpleServer
ConfigureReverseProxy will convert a freshly created SimpleServer into a ReverseProxy. This will use the provided SimpleClient (or a default HTTP SimpleClient) to perform the requests. The ReverseProxyRouterFunc defines HOW the routing will be performed, and must map individual requests to URLs to forward to. The PathPrefix defines the base path to proxy from, with a default of "/" indicating that ALL incoming requests should be proxied. If No Server or Client are provided, default instances will be generated.
func DoReverseProxy ¶
func DoReverseProxy(C *client.SimpleClient, Matcher ReverseProxyRouterFunc, logger *log.Logger) http.HandlerFunc
DoReverseProxy is the backbone of this package, and the reverse Proxy behaviour in general.
This is the http.HandlerFunc which is called on ALL incoming requests
to the reverse proxy. At a high level this function: 1) Determines the forward host, from the incoming request 2) Creates a NEW request, performing a deep copy of the original, including the body 3) Performs this new request, using the provided (or default) SimpleClient to the new Host. 4) Receives the corresponding response, and deep copies it back to the original requester.
func NotFoundHandlerProxyOverride ¶
func NotFoundHandlerProxyOverride(S *server.SimpleServer, c *client.SimpleClient, RouteMatcher ReverseProxyRouterFunc, logger *log.Logger)
NotFoundHandlerProxyOverride will override the NotFound handler of the Server with a reverse proxy lookup function. This will allow the server to attempt to re-route requests it doesn't have a defined route for, while still falling back to a "NotFound" 404 response if there is no defined place to route to.
Types ¶
type ReverseProxyRouterFunc ¶
ReverseProxyRouterFunc represents the Type which must be satisfied by any function which defines the per-request routing behaviours. This must map a given incoming request to a specific forward URL.
func DefinedRulesRouter ¶
func DefinedRulesRouter(RuleSet ReverseProxyRuleSet) ReverseProxyRouterFunc
DefinedRulesRouter will take in a pre-defined set of rules, and will route based on them. This may buy some efficiencies over the LiveFileRouter, as it doesn't need to perform Disk I/O on each request to search for the rules, but this comes with the tradeoff of not being able to edit the rules without restarting the application using this as the router.
func LiveFileRouter ¶
func LiveFileRouter(RulesFilename string) ReverseProxyRouterFunc
LiveFileRouter implements a Reverse Proxy Routing function which will follow rules defined in a JSON file on disk. This rule-set is consulted on each incoming request, allowing any proxy using this to have the routing rules modified without an application restart.
type ReverseProxyRoutingRule ¶
type ReverseProxyRoutingRule struct { PathPrefix string DestinationHost string DestinationPort int NewPrefix string ForbidRoute bool }
ReverseProxyRoutingRule implements a single routing rule to be followed by the Reverse Proxy when re-routing traffic. This will take in a URL path, and return the Host:Port to forward the corresponding request to. This implementation is very basic, effectively effectively just re-routing to a new Host:Port based on the Path Prefix.
func (*ReverseProxyRoutingRule) String ¶
func (R *ReverseProxyRoutingRule) String() string
type ReverseProxyRuleSet ¶
type ReverseProxyRuleSet []ReverseProxyRoutingRule
ReverseProxyRuleSet implements a sortable interface for a set of Reverse Proxy Rules
func (ReverseProxyRuleSet) Find ¶
Find will return either the new Host:Port/Path to forward to or ErrRouteNotFound and nil
func (ReverseProxyRuleSet) Len ¶
func (a ReverseProxyRuleSet) Len() int
func (ReverseProxyRuleSet) Less ¶
func (a ReverseProxyRuleSet) Less(i, j int) bool
Less is defined in "reverse" order, as longer path-prefixes should be matched against first. This allows nested trees of URLs to potentially be proxied further to additional services or servers.
For Example:
/foo/bar -> Forward to service 1 and add a set of URL Query values /foo -> Forward to service 1 and do not add URL Query values
func (ReverseProxyRuleSet) Swap ¶
func (a ReverseProxyRuleSet) Swap(i, j int)
Directories
¶
Path | Synopsis |
---|---|
Command rule-editor implements a basic command-line utility for managing an EasyTLS Proxy Rules file.
|
Command rule-editor implements a basic command-line utility for managing an EasyTLS Proxy Rules file. |