proxytest

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package proxytest provides a recording forward HTTP proxy for tests that assert what a client puts on the wire to a proxy.

A net/http server cannot serve as that proxy: on an absolute-form request it replaces Request.Host with the target's authority and deletes the Host header (RFC 9112 §3.2.2), so the Host the client sent is unobservable. This proxy reads the request head itself, records the request target and the Host header verbatim, and forwards the request to the absolute URL with its Host header unchanged — the way Burp's proxy listener forwards traffic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hit

type Hit struct {
	// RequestTarget is the request-line target as sent, e.g.
	// "http://127.0.0.1:8080/x?q=1".
	RequestTarget string
	// Host is the Host header as sent ("" when absent).
	Host string
}

Hit is one request the proxy received.

type Proxy

type Proxy struct {
	// URL is the proxy's address, e.g. http://127.0.0.1:54321.
	URL *url.URL
	// contains filtered or unexported fields
}

Proxy is a running recording proxy. Close is registered with t.Cleanup.

func New

func New(t testing.TB) *Proxy

New starts a recording proxy on a random loopback port.

func (*Proxy) Close

func (p *Proxy) Close()

Close stops the proxy and waits for in-flight connections.

func (*Proxy) Hits

func (p *Proxy) Hits() []Hit

Hits returns the requests received so far, in arrival order.

Jump to

Keyboard shortcuts

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