proxytest

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxytest is an HTTP proxy that answers CONNECT and nothing else, so a test can show that a client reaches a server only through a proxy, and how the client takes a proxy that refuses it. The Go tests run it in the test process, and the mock control plane runs it for the e2e suites.

The package imports neither testing nor internal/api: the mock is a program, and the tests of internal/api import this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	TLS      *tls.Config // non-nil: the listener speaks TLS
	Username string      // with Password: the Basic credentials a CONNECT must carry
	Password string
	Target   string // non-empty: the only host:port a CONNECT may name
	Upstream string // non-empty: the address every admitted tunnel connects to, in place of the CONNECT target
}

Options says what a Proxy asks of a client and where its tunnels lead. The zero value is a plain proxy that tunnels to any target.

type Proxy

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

Proxy is a CONNECT proxy. Listen makes one, and it answers once Serve runs.

func Listen

func Listen(addr string, opts Options) (*Proxy, error)

Listen binds addr, a host:port as net.Listen takes it, and returns the proxy that Serve runs on it. A TLS listener offers no ALPN protocol, whatever opts.TLS names, because the proxy speaks HTTP/1.1 only.

func (*Proxy) Addr

func (p *Proxy) Addr() net.Addr

Addr returns the address the proxy is bound to, with the port the kernel chose when Listen was given port 0.

func (*Proxy) Serve

func (p *Proxy) Serve(ctx context.Context) error

Serve accepts connections until ctx ends and returns nil then, or the error of a listener that failed before. Either way it has closed the listener and every tunnel, and waited for their goroutines, when it returns.

DECISION: Serve reads the requests itself instead of running an http.Server. A tunnel needs the connection hijacked, and http.Server.Close neither closes a hijacked connection nor waits for its handler.

func (*Proxy) Stats

func (p *Proxy) Stats() Stats

Stats returns the counts so far.

type Stats

type Stats struct {
	Tunnels       int      `json:"tunnels"`        // CONNECTs answered 200
	RefusedAuth   int      `json:"refused_auth"`   // answered 407
	RefusedTarget int      `json:"refused_target"` // answered 403
	OtherRequests int      `json:"other_requests"` // not a CONNECT, answered 405
	Targets       []string `json:"targets"`        // distinct host:port of admitted CONNECTs, sorted
}

Stats counts the answers a Proxy gave. A CONNECT whose upstream could not be dialed, answered 502, is counted nowhere. Each answer is counted before it is sent, so a client that has read one finds it here.

Jump to

Keyboard shortcuts

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