capture

package
v1.261203.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MPL-2.0 Imports: 12 Imported by: 1 module, 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 capture records, as faithfully as possible, what a real client sends to a local fake upstream.

The ground truth is the raw bytes of every accepted TCP connection: a tee below net/http writes everything read from the client to raw/conn-N.in and (optionally) everything written back to raw/conn-N.out. Nothing is parsed, canonicalized, redacted or re-ordered in those files, so header-name casing, header order, duplicate headers, the request line, chunked framing and the exact body bytes survive. index.jsonl only locates each request inside them.

See .design/vmodel-capture.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Out also records the bytes written back to the client
	// (raw/conn-N.out). Callers normally want this on.
	Out bool
	// RequestID makes the capture handler add a `request-id` response header
	// (req_vmodel_<seq>) to responses that do not set one.
	RequestID bool
	// Warn receives one-line diagnostics (an unwritable capture file, a
	// credential that does not look fake). It must not be nil.
	Warn func(string)
}

Options configure a Tap.

type Tap

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

Tap owns one capture directory.

func New

func New(dir string, opts Options) (*Tap, error)

New prepares dir for capture. The directory must not exist or must be empty: a capture is evidence, so it is never mixed with or written over another.

func (*Tap) Close

func (t *Tap) Close() error

Close closes the index. Raw connection files are closed with their connections.

func (*Tap) Dir

func (t *Tap) Dir() string

Dir returns the capture directory.

func (*Tap) Handler

func (t *Tap) Handler(next http.Handler) http.Handler

Handler wraps next. It must be the outermost handler so every request is seen before routing or body binding, including ones next rejects. It never reads the request body and never changes what next sees or answers (apart from the opt-in request-id header).

func (*Tap) Install

func (t *Tap) Install(srv *http.Server)

Install hooks srv so each request can be located in its connection's raw files. It chains any ConnContext / ConnState already set.

func (*Tap) Listener

func (t *Tap) Listener(l net.Listener) net.Listener

Listener wraps l so every accepted connection is teed into raw/conn-N.in (and raw/conn-N.out when Options.Out is set).

func (*Tap) SetMeta

func (t *Tap) SetMeta(meta map[string]any) error

SetMeta writes meta.json (replacing any previous one) with the caller's description of the run plus the creation time. Safe to call once the listener address is known.

Jump to

Keyboard shortcuts

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