proxy

package module
v0.0.0-...-e927470 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: Apache-2.0 Imports: 20 Imported by: 11

Documentation

Index

Constants

View Source
const (

	// MetricDialUpstream is the Server-Timing metric to record milliseconds to
	// dial upstream site when handling a CONNECT request.
	MetricDialUpstream = "dialupstream"

	// DialTimeoutHeader is a header that sets a timeout for dialing upstream
	// (only respected on CONNECT requests). The timeout is specified in
	// milliseconds.
	DialTimeoutHeader = "X-Lantern-Dial-Timeout"
)

Variables

This section is empty.

Functions

func OnFirstOnly

func OnFirstOnly(filter filters.Filter) filters.Filter

OnFirstOnly returns a filter that applies the given filter only on the first request on a given connection.

Types

type BufferSource

type BufferSource interface {
	Get() []byte
	Put(buf []byte)
}

BufferSource is a source for buffers used in reading/writing.

type DialFunc

type DialFunc func(ctx context.Context, isCONNECT bool, network, addr string) (conn net.Conn, err error)

DialFunc is the dial function to use for dialing the proxy.

type Opts

type Opts struct {
	// IdleTimeout, if specified, lets us know to include an appropriate
	// KeepAlive: timeout header in the responses.
	IdleTimeout time.Duration

	// BufferSource specifies a BufferSource, leave nil to use default.
	BufferSource BufferSource

	// Filter is an optional Filter that will be invoked for every Request
	Filter filters.Filter

	// OnError, if specified, can return a response to be presented to the client
	// in the event that there's an error round-tripping upstream. If the function
	// returns no response, nothing is written to the client. Read indicates
	// whether the error occurred on reading a request or not. (HTTP only)
	OnError func(ctx filters.Context, req *http.Request, read bool, err error) *http.Response

	// OKWaitsForUpstream specifies whether or not to wait on dialing upstream
	// before responding OK to a CONNECT request (CONNECT only).
	OKWaitsForUpstream bool
	// OKSendsServerTiming specifies whether or not to send back Server-Timing header
	// when responding OK to CONNECT request.
	// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing.
	// The only metric for now is dialupstream, so the value is in the form "dialupstream;dur=42".
	OKSendsServerTiming bool

	// Dial is the function that's used to dial upstream.
	Dial DialFunc

	// ShouldMITM is an optional function for determining whether or not the given
	// HTTP CONNECT request to the given upstreamAddr is eligible for being MITM'ed.
	ShouldMITM func(req *http.Request, upstreamAddr string) bool

	// MITMOpts, if specified, instructs proxy to attempt to man-in-the-middle
	// connections and handle them as an HTTP proxy. If the connection cannot be
	// mitm'ed (e.g. Client Hello doesn't include an SNI header) or if the
	// contents isn't HTTP, the connection is handled as normal without MITM.
	MITMOpts *mitm.Opts
}

Opts defines options for configuring a Proxy

type Proxy

type Proxy interface {
	// Handle handles a single connection, with in specified separately in case
	// there's a buffered reader or something of that sort in use.
	Handle(ctx context.Context, in io.Reader, conn net.Conn) error

	// Connect opens a CONNECT tunnel to the origin without requiring a CONNECT
	// request to first be sent on conn. It will not reply with CONNECT OK.
	Connect(ctx context.Context, in io.Reader, conn net.Conn, origin string) error

	// Serve runs a server on the given Listener
	Serve(l net.Listener) error

	// ApplyMITMOptions updates the configuration of the MITM interceptor
	ApplyMITMOptions(MITMOpts *mitm.Opts) error
}

Proxy is a proxy that can handle HTTP(S) traffic

func New

func New(opts *Opts) (newProxy Proxy, mitmErr error)

New creates a new Proxy configured with the specified Opts. If there's an error initializing MITM, this returns an mitmErr, however the proxy is still usable (it just won't MITM).

type RequestAware

type RequestAware interface {
	// OnRequest allows this connection to make modifications to the request as
	// needed
	OnRequest(req *http.Request)
}

RequestAware is an interface for connections that are able to modify requests before they're sent on the connection.

type ResponseAware

type ResponseAware interface {
	// OnResponse allows this connection to learn about responses
	OnResponse(req *http.Request, resp *http.Response, err error)
}

ResponseAware is an interface for connections that are interested in knowing about responses received on the connection.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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