proxy

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProxyMode

type ProxyMode int

ProxyMode indicates whether the proxy is recording or testing.

const (
	// ModeRecord captures baseline snapshots.
	ModeRecord ProxyMode = iota
	// ModeTest compares live responses against stored snapshots.
	ModeTest
)

func (ProxyMode) String

func (m ProxyMode) String() string

String returns the human-readable name of the mode.

type ProxyServer

type ProxyServer struct {
	Addr          string
	Mode          ProxyMode
	CAManager     *ca.CAManager
	Handler       RequestHandler
	InjectHeaders map[string]string // headers to inject into outgoing requests
	MaxBodySize   int64             // max response body size in bytes (0 = unlimited)
	// contains filtered or unexported fields
}

ProxyServer is an HTTP/HTTPS forward proxy.

func NewProxyServer

func NewProxyServer(addr string, mode ProxyMode, cam *ca.CAManager, handler RequestHandler) *ProxyServer

NewProxyServer creates a ProxyServer ready to be started.

func (*ProxyServer) Shutdown

func (p *ProxyServer) Shutdown(ctx context.Context) error

Shutdown drains in-flight requests with a 30s timeout.

func (*ProxyServer) Start

func (p *ProxyServer) Start(ctx context.Context) error

Start listens for proxy connections. Blocks until context is cancelled.

type RecordHandler

type RecordHandler struct {
	HashComputer  *hash.HashComputer
	SnapshotStore *snapshot.SnapshotStore
	EnvExpander   *envvar.Expander // optional, collapses URLs to {{VAR}} placeholders
	Redactor      *redact.Redactor // optional, scrubs PII/secrets before saving
}

RecordHandler handles intercepted request/response pairs in record mode by computing a request hash and persisting the response as a snapshot.

func NewRecordHandler

func NewRecordHandler(hc *hash.HashComputer, ss *snapshot.SnapshotStore) *RecordHandler

NewRecordHandler creates a RecordHandler with the given hash computer and snapshot store.

func (*RecordHandler) HandleRequest

func (h *RecordHandler) HandleRequest(req *http.Request, resp *http.Response) error

HandleRequest computes a deterministic hash from the request, reads the response body, and persists the snapshot entry keyed by host and hash.

type RequestHandler

type RequestHandler interface {
	HandleRequest(req *http.Request, resp *http.Response) error
}

RequestHandler processes intercepted request/response pairs.

type TestHandler

type TestHandler struct {
	HashComputer    *hash.HashComputer
	SnapshotStore   *snapshot.SnapshotStore
	DiffEngine      *diff.DiffEngine
	ApprovalManager *approval.ApprovalManager
	EnvExpander     *envvar.Expander // optional, collapses URLs before hashing
	Summary         *snapshot.TestSummary
	HitHashes       []string // hashes that were matched during this test run
	// contains filtered or unexported fields
}

TestHandler handles intercepted request/response pairs in test mode by comparing live responses against stored snapshots and tracking results.

func NewTestHandler

NewTestHandler creates a TestHandler wired to the given components.

func (*TestHandler) GetHitHashes

func (h *TestHandler) GetHitHashes() []string

GetHitHashes returns the list of snapshot hashes that were matched.

func (*TestHandler) GetSummary

func (h *TestHandler) GetSummary() snapshot.TestSummary

GetSummary returns a copy of the current test summary.

func (*TestHandler) HandleRequest

func (h *TestHandler) HandleRequest(req *http.Request, resp *http.Response) error

HandleRequest computes the request hash, looks up the stored snapshot, and compares the live response against it. Counters are updated thread-safely.

Jump to

Keyboard shortcuts

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