Skip to main content

Module http_client

Module http_client 

Source
Expand description

Shared reqwest::Client factory with project-wide timeouts.

Every HTTP call in pakx ultimately funnels through reqwest::Client. Constructing one via Client::new() is convenient but leaves both the request timeout and the connect timeout at reqwest’s default of none — so a half-open TCP connection to a slow / blackholed registry will hang the CLI indefinitely. The user can’t even Ctrl+C out of the install loop cleanly because the futures are parked on the network, not on a tokio timer.

This module centralises client construction so:

  • request_timeout defaults to 60s — long enough for an ordinary registry round-trip (federated search + metadata fetch) but short enough that a hung CI doesn’t sit for 30 minutes before the job scheduler kills it.
  • connect_timeout defaults to 15s — fail fast on DNS / TCP issues instead of letting the request-timeout absorb the connect cost.
  • Long-running uploads (pakx publish, in particular the tarball PUT) can opt into a longer request timeout via http_client_with_timeout.

All other call sites that previously used reqwest::Client::new() must route through http_client so the timeout discipline is uniform across install, publish, search, outdated, audit, add, info, upgrade, and the registry sources. Auditing for drift is then a single grep Client::new across the workspace.

Constants§

DEFAULT_CONNECT_TIMEOUT
Default TCP/TLS connect timeout. Separate from the request timeout so DNS / unreachable-host errors surface in seconds rather than being absorbed into the full 60s request budget.
DEFAULT_REQUEST_TIMEOUT
Default request-level timeout applied to every client built via http_client.
UPLOAD_REQUEST_TIMEOUT
Request timeout for tarball uploads (pakx publish PUT). The default 60s is too aggressive for a 50 MiB upload over a slow residential uplink; 5 minutes matches the registry’s own server- side limit.

Functions§

http_client
Build a reqwest::Client with the project-wide default timeouts.
http_client_with_timeout
Build a reqwest::Client with a caller-supplied request timeout and the project-wide default connect timeout.