httpproxy

package
v0.0.0-...-44b4573 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPort is the port number the daemon will listen on in the absence of port number specified by user.
	DefaultPort = 210
	// TestPort is used exclusively by test cases to configure daemon under testing.
	TestPort = 54112
	// IOTimeout is the maximum duration of an entire proxy request. The number took inspiration from the default settings in Squid software.
	IOTimeout = time.Duration(10 * time.Minute)
	// MaxRequestBodyBytes is the maximum size accepted for the entire request body of an HTTP proxy request.
	// The size does not apply to HTTPS proxy request (HTTP CONNECT).
	MaxRequestBodyBytes = 2 * 1024 * 1024
)

Variables

This section is empty.

Functions

func TestHTTPProxyDaemon

func TestHTTPProxyDaemon(daemon *Daemon, t testingstub.T)

TestHTTPProxyDaemon is used exclusively by test case to run a comprehensive test routine for the daemon's functions. The daemon must have already been completed with all of its configuration and successfully initialised. See httpproxy_test.go for the daemon initialisation routine.

Types

type Daemon

type Daemon struct {
	// Address is the IP address to listen on, e.g. 0.0.0.0 to listen on all network interfaces.
	Address string `json:"Address"`
	// Port to listen on.
	Port int `json:"Port"`
	// PerIPLimit is the approximate number of requests a client (identified by its IP) can make in a second.
	PerIPLimit int `json:"PerIPLimit"`
	// AllowFromCidrs is a list of CIDRs that client address must reside in to be eligible to use this HTTP proxy daemon.
	AllowFromCidrs []string `json:"AllowFromCidrs"`
	// Processor is a toolbox command processor that collects client subject reports for its store&forward message processor app.
	// Though the HTTP proxy daemon itself is incapable of executing app commands, the daemon will however subjects of the message
	// processor (computers) to use the proxy daemon. This saves the effort of having to figure out users' Internet CIDR block
	// and placing them into AllowFromCidrs.
	// This mechanism exists in the DNS daemon in a similar form.
	CommandProcessor *toolbox.CommandProcessor `json:"-"`

	// DNSDaemon is an initialised DNS daemon that will provide protection against advertising, malware, and tracking to this web proxy.
	DNSDaemon *dnsd.Daemon `json:"-"`
	// contains filtered or unexported fields
}

Daemon offers an HTTP proxy capable of handling both HTTP and HTTPS destinations.

func (*Daemon) CheckClientIPMiddleware

func (daemon *Daemon) CheckClientIPMiddleware(next http.HandlerFunc) http.HandlerFunc

CheckClientIPMiddleware decorates the HTTP handler with an additional check of client IP address, and calls the next handler only if the client IP is among the allowed. If the client IP is not allowed, the decorated HTTP handler will respond politely with an appropriate HTTP status code.

func (*Daemon) Initialise

func (daemon *Daemon) Initialise() error

Initialise validates configuration parameters and initialises the internal state of the daemon.

func (Daemon) ProxyHandler

func (daemon Daemon) ProxyHandler(w http.ResponseWriter, r *http.Request)

ProxyHandler is an HTTP handler function that implements an HTTP proxy capable of handling HTTPS as well.

func (*Daemon) StartAndBlock

func (daemon *Daemon) StartAndBlock() error

StartAndBlock starts a web server with a specially crafted handler to serve HTTP proxy clients. The function will block caller until Stop is called.

func (*Daemon) Stop

func (daemon *Daemon) Stop()

Stop the daemon.

Jump to

Keyboard shortcuts

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