proxychaintest

package
v1.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package proxychaintest provides an in-process HTTP CONNECT forward proxy for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClosedAddr added in v1.6.0

func ClosedAddr(t *testing.T) string

ClosedAddr returns a local address nothing listens on.

func FirstBytes added in v1.6.0

func FirstBytes(t *testing.T, n int) (string, <-chan []byte)

FirstBytes starts a TCP server that reports the first n bytes the client sends on the first connection that sends them (a protocol header, a TLS ClientHello), then hangs up. Closed on test cleanup.

func HostOf

func HostOf(rawURL string) string

HostOf returns the host:port of a URL.

func WithCreds

func WithCreds(rawURL, user, pass string) string

WithCreds rewrites a server URL to carry userinfo.

Types

type Proxy

type Proxy struct {
	*httptest.Server

	// Reject, if set, is consulted for each CONNECT; a non-zero status short
	// circuits with that status and headers.
	Reject func(target string) (int, http.Header)
	// Hold, if set, is closed by the test to release a CONNECT that is
	// deliberately left unanswered.
	Hold chan struct{}
	// contains filtered or unexported fields
}

Proxy is an httptest forward proxy: CONNECT is hijacked and piped to the requested authority, plain requests are forwarded absolute-URI style. It records every CONNECT authority and Proxy-Authorization it saw.

func New

func New(t *testing.T, useTLS bool) *Proxy

New starts a Proxy, closed on test cleanup.

func (*Proxy) Auths

func (p *Proxy) Auths() []string

Auths returns the Proxy-Authorization header of every CONNECT seen so far.

func (*Proxy) Connects

func (p *Proxy) Connects() []string

Connects returns every CONNECT authority seen so far.

Jump to

Keyboard shortcuts

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