switchproxy

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: AGPL-3.0 Imports: 12 Imported by: 0

README

SwitchProxy

SwitchProxy is a proxy that allows for sending the data to multiple endpoints with full HTTP logging HTTP Proxy with MITM and WriteOnly connections

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout value used when a Timeout is not
	// specified in NewProxy.
	DefaultTimeout = time.Second * time.Duration(15)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(Result)

Handler is a function alias that can be passed a Result for processing.

type Parameter

type Parameter interface {
	// contains filtered or unexported methods
}

Parameter is an interface that helps define config options for the Proxy struct.

func TLS

func TLS(cert, key string) Parameter

TLS creates a config paramater with the specified Key and Value file paths.

type Proxy

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

Proxy is a struct that represents a stacked proxy that allows a forwarding proxy with secondary read only Switch connections that allow logging and storing the connection data.

func New

func New(listen string, c ...Parameter) *Proxy

New creates a new Proxy instance from the specified listen address and optional parameters.

func NewContext

func NewContext(x context.Context, listen string, c ...Parameter) *Proxy

NewContext creates a new Proxy instance from the specified listen address and optional parameters. This function allows the caller to specify a context to specify when to shutdown the Proxy.

func (*Proxy) AddSecondary

func (p *Proxy) AddSecondary(s ...*Switch)

AddSecondary adds an additional one-way Switch context.

func (*Proxy) Primary

func (p *Proxy) Primary(s *Switch)

Primary sets the primary Proxy Switch context.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP satisfies the http.Handler interface.

func (*Proxy) Start

func (p *Proxy) Start() error

Start starts the Server listening loop and returns an error if the server could not be started. Only returns an error if any IO issues occur during operation.

func (*Proxy) Stop

func (p *Proxy) Stop() error

Stop attempts to gracefully close and Stop the proxy and all remaining connextions.

type Result

type Result struct {
	Headers http.Header `json:"headers"`
	IP      string      `json:"ip"`
	UUID    string      `json:"uuid"`
	Path    string      `json:"path"`
	Method  string      `json:"method"`
	URL     string      `json:"url"`
	Content []byte      `json:"content"`
	Status  uint16      `json:"status"`
}

Result is a struct that contains the data of the resulting Switch operation to be passed to Handlers.

func (Result) IsResponse

func (r Result) IsResponse() bool

IsResponse is a function that returns true if the Result is for a response.

type Switch

type Switch struct {
	Pre  Handler
	Post Handler

	url.URL
	// contains filtered or unexported fields
}

Switch is a struct that represents a connection between proxy services. This struct contains mapping and functions to capture input and output.

func NewSwitch

func NewSwitch(target string) (*Switch, error)

NewSwitch creates a switching context that allows the connection to be proxied to the specified server.

func NewSwitchTimeout

func NewSwitchTimeout(target string, t time.Duration) (*Switch, error)

NewSwitchTimeout creates a switching context that allows the connection to be proxied to the specified server. This function will set the specified timeout.

func (*Switch) RemoveRewrite

func (s *Switch) RemoveRewrite(from string)

RemoveRewrite removes the URL rewrite from the Switch.

func (*Switch) Rewrite

func (s *Switch) Rewrite(from, to string)

Rewrite adds a URL rewrite from the Switch. If a URL starts with the 'from' paramater, it will be replaced with the 'to' paramater, only if starting with on the URL path.

type Timeout

type Timeout time.Duration

Timeout is a time.Duration alias of a configuration option.

Directories

Path Synopsis
proxy module

Jump to

Keyboard shortcuts

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