Help us shape the future of Go! Take the 2026 Go Developer Survey

proxy

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package proxy forwards connections to the internet with HTTP CONNECT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, listener net.Listener, options Options) error

Serve accepts connections until the context ends.

Types

type Log added in v1.3.0

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

Log writes each target the proxy connected to or refused to a writer once, and keeps them with how often and when last they were used. It writes what the guest asked for, not what went through.

func NewLog added in v1.3.0

func NewLog(w io.Writer) *Log

NewLog returns a Log that writes to w.

func (*Log) Closed added in v1.5.0

func (l *Log) Closed(target string)

Closed notes when a connection to a target ended. It is an OnClosed function.

func (*Log) Connected added in v1.3.0

func (l *Log) Connected(target string)

Connected logs a target the proxy connected to. It is an OnConnected function.

func (*Log) Refused added in v1.3.0

func (l *Log) Refused(target string)

Refused logs a target the proxy refused. It is an OnRefused function.

func (*Log) Summarize added in v1.5.0

func (l *Log) Summarize()

Summarize writes for each target how often the proxy connected to it or refused it, and when last. Call it once the proxy has stopped, so that no connection is still open.

func (*Log) Targets added in v1.3.0

func (l *Log) Targets() (connected, refused []string)

Targets returns the targets the proxy connected to and those it refused, each in the order the proxy first met them.

type Options

type Options struct {
	// Allow is called with the host name and port of each CONNECT request
	// and returns whether they may be reached. Nil allows everything.
	Allow func(host, port string) bool
	// OnConnected is called with the host:port of each request once the
	// proxy reached it, before the tunnel opens.
	OnConnected func(target string)
	// OnRefused is called with the host:port of each refused request.
	OnRefused func(target string)
	// OnClosed is called with the host:port of each request the proxy
	// reached once its tunnel has closed.
	OnClosed func(target string)
	// Hint is a line added to each refusal, such as where to allow the host.
	Hint string
	// Resolve looks a host name up. Nil uses the system resolver.
	Resolve func(ctx context.Context, host string) ([]net.IP, error)
	// Local returns the handler that answers a target itself, over HTTP in
	// the tunnel, or nil for a target the proxy connects to. A target it
	// answers needs no place on the allow list.
	Local func(host, port string) http.Handler
	// Pinned returns the addresses a name stands for without asking DNS,
	// such as localhost. They are dialed even when they are not public. Nil,
	// or no addresses, resolves the name as usual.
	Pinned func(host, port string) []net.IP
}

Options control what the proxy lets through.

Jump to

Keyboard shortcuts

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