Skip to main content

Module net_capture

Module net_capture 

Source
Expand description

Process-wide, opt-in HTTP capture sink for dev tooling.

The scripting HTTP layer (lumen-script’s fetch() / http() builtins) unconditionally reports request/response lifecycle events to record. When no sink has been installed - the default in a release build, and always when lumen-devtools is not compiled in - record is a single atomic load plus branch and drops the event on the floor, so there is zero capture cost and no unbounded buffer growth.

A dev-only consumer (the devtools Network tab) calls init_net_capture once at startup to install the sink, then drains accumulated events each tick via drain into its own bounded ring. This mirrors the crate::signals external-mutation channel pattern: one global OnceLock sender, one OnceLock<Mutex<Receiver>>, both idempotent.

Enums§

NetEvent
One HTTP lifecycle event emitted by the scripting fetch/http layer.

Functions§

drain
Drain up to max pending events (oldest first). Returns empty when the sink was never installed or nothing is queued.
init_net_capture
Idempotently install the capture sink. Safe to call multiple times; only the first call creates the channel. After this returns, record starts forwarding events for drain to collect.
record
Report an HTTP lifecycle event. No-op (one atomic load + branch) until init_net_capture has run, so release builds without dev tooling pay nothing and never accumulate an unbounded buffer.