rsrp

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2019 License: MIT Imports: 6 Imported by: 0

README

Really Simple Reverse Proxy

A configuration-based tool to route HTTP(S) traffic to other servers/services based on the URL path of incoming requests.

Note that this is best suited for API servers; HTML becomes more difficult because the paths change.

Example

See the example project with a small HTTP server using rsrp to proxy two other simple HTTP services.

Configuration Specification

JSON is used for the default configuration format. Other formats can be supported (see the types in rules.go).

{
  "routes": [
    {
      "match": "regex",
      "rewrite": {
        "from": "regex with capturing groups",
        "to": "path with $"
      },
      "destination": "scheme, hostname, and (optional) port"
    }
  ]
}

An array of routes are expected. Routes are queried in the order specified in this array. Only the first matching route is used.

Each route has a match field which will match against the incoming request URL path.

Each route has a rewrite rule.

A rewrite rule has a from field which will capture parts of the incoming request URL path.

A rewrite rule has a to field which will build up the proxied URL path. Capture groups are specified using 1-indexed $ syntax.

Each route has a destination, which must have the scheme and hostname of the destination server/service. A port can also be specified.

Version History

1.1.1 (2019-05-04)
  • Bugfix for handling WebSockets
1.1.0 (2019-05-03)
  • Initial support for WebSockets
1.0 (2018-12-22)
  • MVP reverse proxy with simple regex-based rewrite rules

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertRules

func ConvertRules(routes []RouteRuleConfig) (routeRules *[]RouteRule, err error)

ConvertRules converts RouteRuleConfigs to RouteRules

func RedirectRequest

func RedirectRequest(r *http.Request, newURL string) (newRequest *http.Request, err error)

RedirectRequest copies a request and changes the URL

func RouteAll

func RouteAll(rules []RouteRule) func(http.ResponseWriter, *http.Request)

RouteAll routes all requests based on the RouteRules provided

Types

type Config

type Config struct {
	Routes []RouteRuleConfig `json:"routes"`
}

Config holds configuration details for the reverse proxy

type RewriteRule

type RewriteRule struct {
	Input  *regexp.Regexp
	Output string
}

A RewriteRule describes how to modify the path for a request

func NewRewriteRule

func NewRewriteRule(config RewriteRuleConfig) (rule *RewriteRule, err error)

NewRewriteRule converts a RewriteRuleConfig to a RewriteRule

type RewriteRuleConfig

type RewriteRuleConfig struct {
	Input  string `json:"from"`
	Output string `json:"to"`
}

A RewriteRuleConfig is the on-disk representation of a RewriteRule

type RouteRule

type RouteRule struct {
	Match            *regexp.Regexp
	Rewrite          RewriteRule
	Destination      string
	WebSocketOptions relay.Options
}

A RouteRule describes which paths to match, how to rewrite the request, and where to reroute the request

func NewRouteRule

func NewRouteRule(config RouteRuleConfig) (rule *RouteRule, err error)

NewRouteRule converts a RouteRuleConfig to a RouteRule

func (RouteRule) RewriteLocation

func (rule RouteRule) RewriteLocation(path string) string

RewriteLocation converts a request path to the redirected location

func (RouteRule) RewritePath

func (rule RouteRule) RewritePath(path string) string

RewritePath converts a request path to the redirected path

type RouteRuleConfig

type RouteRuleConfig struct {
	Match       string            `json:"match"`
	Rewrite     RewriteRuleConfig `json:"rewrite"`
	Destination string            `json:"destination"`
}

A RouteRuleConfig is the on-disk representation of a RouteRule

Directories

Path Synopsis
json command
plaintext command
Package relay implements a rerouted WebSocket connection handler
Package relay implements a rerouted WebSocket connection handler

Jump to

Keyboard shortcuts

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