proxy

package
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MIT Imports: 10 Imported by: 2

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 specific "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 actually perform the request, before writing the response back to the original request source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureReverseProxy

func ConfigureReverseProxy(S *server.SimpleServer, Client *client.SimpleClient, Verbose bool, RouteMatcher ReverseProxyRouterFunc, PathPrefix string, Middlewares ...server.MiddlewareHandler)

ConfigureReverseProxy will convert a freshly created SimpleServer into a ReverseProxy. This will use either the provided SimpleClient (or a default HTTP SimpleClient) to perform the requests. The ReverseProxyRouterFunc defines HOW the routing will be peformed, 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. Finally, any middlewares desired can be added, noting that the "MiddlewareDefaultLogger" is applied in all cases.

If No Server or Client are provided, default instances will be generated.

func DoReverseProxy

func DoReverseProxy(C *client.SimpleClient, IsTLS bool, Matcher ReverseProxyRouterFunc, verbose bool) 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, excluding 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.

Types

type ReverseProxyRouterFunc

type ReverseProxyRouterFunc func(*http.Request) (string, error)

ReverseProxyRouterFunc represents the Type which must be satisfied by any function which defines the per-request routing behaviours. This must map a given request to a specific IP:Port host and leave the Path unchanged.

func DefinedRulesRouter

func DefinedRulesRouter(RuleSet []ReverseProxyRoutingRule) 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
}

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

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.

Jump to

Keyboard shortcuts

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