proxy

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package proxy provides methods for creating a proxy programmatically.

Index

Constants

View Source
const (
	// EnvTLSKey defines the name for the environment variable that holds the
	// root TLS key.
	EnvTLSKey = `HYPERFOX_TLS_KEY`
	// EnvTLSCert defines the name for the environment variable that holds the
	// root TLS certificate..
	EnvTLSCert = `HYPERFOX_TLS_CERT`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyWriteCloser

type BodyWriteCloser interface {
	NewWriteCloser(*http.Response) (io.WriteCloser, error)
}

BodyWriteCloser interface returns a io.WriteCloser where a copy of the response body will be written. The io.WriteCloser's Close() method will be called after the body has been written entirely.

destination -> ... -> BodyWriteCloser -> client -> ...

type Director

type Director interface {
	Direct(*http.Request) error
}

Director interface gets a reference of the http.Request sent by an user before sending it to the destination. The Direct() method may modify the client's request.

client -> Director -> destination

type Interceptor

type Interceptor interface {
	Intercept(*http.Response) error
}

Interceptor interface gets a reference of the http.Response sent by the destination before arriving to the client. The Interceptor() method may modify the destination's response.

destination -> Interceptor -> ... -> client -> ...

type Logger

type Logger interface {
	Log(*ProxiedRequest) error
}

Logger interface gets a reference of the ProxiedRequest after the response has been writte to the client.

The Logger() method must not modify any *ProxiedRequest properties.

destination -> ... -> client -> Logger

type ProxiedRequest

type ProxiedRequest struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	Response       *http.Response
}

ProxiedRequest struct provides properties for executing a *http.Request and proxying it into a http.ResponseWriter.

type Proxy

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

Proxy struct provides methods and properties for creating a proxy programatically.

func NewProxy

func NewProxy() *Proxy

NewProxy creates and returns a Proxy reference.

func (*Proxy) AddBodyWriteCloser

func (p *Proxy) AddBodyWriteCloser(wc BodyWriteCloser)

AddBodyWriteCloser appends a struct that satisfies the BodyWriteCloser interface to the list of body write closers.

func (*Proxy) AddDirector

func (p *Proxy) AddDirector(dir Director)

AddDirector appends a struct that satisfies the Director interface to the list of directors.

func (*Proxy) AddInterceptor

func (p *Proxy) AddInterceptor(dir Interceptor)

AddInterceptor appends a struct that satisfies the Interceptor interface to the list of interceptors.

func (*Proxy) AddLogger

func (p *Proxy) AddLogger(dir Logger)

AddLogger appends a struct that satisfies the Logger interface to the list of loggers.

func (*Proxy) Reset

func (p *Proxy) Reset()

Reset clears the list of interfaces.

func (*Proxy) ServeHTTP

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

ServeHTTP catches a client request and proxies it to the destination server, then waits for the server's answer and sends it back to the client.

(this method should not be called directly).

func (*Proxy) SetCustomDNS

func (p *Proxy) SetCustomDNS(server string) error

SetCustomDNS sets a DNS server that bypasses the OS settings

func (*Proxy) Start

func (p *Proxy) Start(addr string) error

Start creates an HTTP proxy server that listens on the given address.

func (*Proxy) StartSplit

func (p *Proxy) StartSplit(addr string) error

func (*Proxy) StartTLS

func (p *Proxy) StartTLS(addr string) error

StartTLS creates an HTTPs proxy server that listens on the given address.

func (*Proxy) Stop

func (p *Proxy) Stop()

Stop terminates a running proxy

Jump to

Keyboard shortcuts

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