purpleproxy

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 13 Imported by: 0

README

Purple Proxy - An extensive HTTP/HTTPS/SOCKS4/SOCKS4a/SOCKS5 Proxy Framework

Documentation

Index

Constants

View Source
const (
	ProtoHttp = "HTTP"
)

Supported ProxyConfig.Protocol protocols.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthEvent added in v0.3.0

type AuthEvent struct {
	Username string
	Password string
}

EventHandler.Auth event data

type Context added in v0.3.0

type Context interface {
	// Connection ID
	ID() uint64

	// Returns Proxy associated with this context.
	Proxy() Proxy

	// Client remote address.
	RemoteAddr() string

	// Return amount of bytes client sent/received.
	//
	// When invoked, bytes are flushed and set to 0.
	Bytes() uint64

	// Done is called when the connection is closed.
	Done() <-chan struct{}
}

type EventHandler added in v0.3.0

type EventHandler struct {
	// Connect is invoked on initial connect from remote client.
	// It receives the remote address of the connecting client.
	// Returning false will close the connection.
	Connect func(Context) bool

	// AuthEvent allows for authorization via remote address or username/password.
	// Returning false will close the connection with the corresponding response for that protocol.
	//
	// If AuthEvent == nil, authorization is disabled.
	Auth func(Context, AuthEvent) bool

	// Dial is invoked before dialing the connection to the destination host.
	//
	// The host parameter is the original host in which the Dial would connect to.
	// The string to be returned is the host:port in which you wish the proxy to forward the connection to.
	Dial func(ctx Context, host string) string

	// Disconnect is invoked when the client or server closes the connection.
	Disconnect func(Context)
}

type HttpProxy

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

func (*HttpProxy) Addr added in v0.3.0

func (h *HttpProxy) Addr() string

func (*HttpProxy) Close

func (h *HttpProxy) Close() error

Close invokes the shutdown method for the proxy server.

func (*HttpProxy) Config added in v0.3.0

func (h *HttpProxy) Config() ProxyConfig

func (*HttpProxy) Start

func (h *HttpProxy) Start(addr string) error

Start the proxy server listening on the provided addr.

type Proxy

type Proxy interface {
	Start(string) error
	Close() error
	Addr() string
	Config() ProxyConfig
}

All proxy protocols implement Proxy interface

func NewProxy

func NewProxy(cfg ProxyConfig) (Proxy, error)

Returns a new Proxy interface with a type specific to ProxyConfig.Protocol.

type ProxyConfig

type ProxyConfig struct {
	// Proxy Protocol.
	//
	// Supported protocols: ProtoHttp.
	Protocol string

	// Timeout for dialing connection to destination host.
	//
	// Default value: 30 seconds.
	DialTimeout time.Duration

	// Timeout for reading from both client and server.
	//
	// Default value: 30 seconds.
	ReadTimeout time.Duration

	// Timeout for writing to both client and server.
	//
	// Default value: 30 seconds.
	WriteTimeout time.Duration

	// If true, ErrorHandler logging will be verbose.
	Debug bool

	// hop-by-hop headers are to be consumed by a proxy and not sent to the destination server.
	//
	// When true, the headers will be forwarded to the destination server.
	// This can be useful when proxying to another proxy server that will need to handle them.
	ForwardHopHeaders bool

	// If true, Proxy will act as a forwarding proxy to another receiving proxy.
	//
	// ForwardHopHeaders will be set to true and all requests will be written to the wire in proxy format.
	Forwarder bool

	// You can use the EventHandler to register any available events that will be invoked by the Proxy.
	Events *EventHandler

	// ErrorHandler receives any returned errors from the Proxy
	//
	// This function is called by multiple goroutines and is not thread safe.
	// If you wish to write to a file or another output that requires thread-safety
	// use a locking mechanism such as sync.Mutex.
	ErrorHandler func(error, Context)
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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