Skip to main content

Module http

Module http 

Source
Expand description

Canonical ureq::Agent construction + named HTTP timeout constants.

Before this module, ureq::AgentBuilder::new().timeout(...).build() was inlined at 7 production sites (server_client, daemon, oci x3, upgrade x2) with three of the timeouts already drifted. Worse, cfgd/src/ai/client.rs used bare ureq::post(...) with no timeout at all — the Anthropic call could hang the CLI indefinitely. Using these constants + http_agent replaces every inline Duration::from_secs(...) literal and keeps future timeout changes in one place.

Constants§

HTTP_AI_TIMEOUT
Anthropic API requests from cfgd generate and cfgd ai. Claude latency for agentic tool use is normally a few seconds; 120s is a ceiling for pathological slow networks. Must have some timeout — before this constant the request had none at all.
HTTP_API_TIMEOUT
Device gateway API calls (checkin, drift, enrollment) — small JSON payloads. Kept short because the gateway is nearby and responses are small.
HTTP_OCI_TIMEOUT
OCI registry blob / manifest operations (push, pull, multi-platform index). Module layers and image blobs can be hundreds of MiB; 300s accommodates cold caches and slow registry peers.
HTTP_UPGRADE_TIMEOUT
GitHub Releases API queries + binary archive downloads for self-upgrade. 300s covers slow mirrors; the streaming download applies per-chunk.
HTTP_WEBHOOK_TIMEOUT
Outbound webhook notifications (drift alerts, check-in callbacks). Short — the caller doesn’t wait on user-visible output; a slow peer should not starve the daemon’s notification loop.

Functions§

http_agent
Build a ureq::Agent with timeout applied. Exists so every call site that wants a timeout can use one line and we can change AgentBuilder configuration (user-agent defaults, connection pooling, TLS options) in exactly one place if it becomes necessary.