Skip to main content

Module network_profile_runtime

Module network_profile_runtime 

Source
Expand description

Runtime network-profile switching API Runtime network-profile switching API.

Profiles like mobile_3g / lossy_network / extremely_poor come from mockforge_core::network_profiles::NetworkProfileCatalog. They were previously selectable only via --network-profile at startup, which meant a hosted-mock operator couldn’t probe how their consumer behaves on a slow network without redeploying.

This module exposes the catalog over HTTP and adds a middleware that applies the active profile’s latency on every request. Bandwidth and loss simulation are not yet wired through this path — latency is the 90% case for “what if my upstream gets slow” testing and is the cheapest to add without per-byte accounting.

§Endpoints

  • GET /__mockforge/api/network-profiles — list available profiles
  • GET /__mockforge/api/network-profiles/active — current active profile (or 204 if none)
  • POST /__mockforge/api/network-profiles/{name}/activate — switch to profile
  • POST /__mockforge/api/network-profiles/deactivate — clear

Structs§

NetworkProfileRuntimeState
Cheap-to-clone shared state holding the catalog (immutable) plus the currently active profile (mutable).

Functions§

network_profile_api_router
Build the network-profile runtime API router. Mount under /__mockforge/api/network-profiles.
network_profile_middleware
Middleware that applies the active profile’s latency before passing to the next layer. Reads NetworkProfileRuntimeState::active() per request — a swap takes effect on the very next call.