rskit-httpclient
Async HTTP client for rskit with redacting auth, headers, injected resilience policies, destination hardening, and error handling.
Features
- Async HTTP client built on
reqwest - Support for Bearer, Basic, and API key authentication with redacted secret storage
- Configurable timeouts, headers, and redirect behavior
- Explicit TLS trust, identity, and minimum-version configuration via
rskit-security - Optional
rskit-resilience::Policyintegration for retry, timeout, circuit breaker, and rate limiting - URL building with base URL support and outbound destination validation
- Bounded response body reads to avoid unbounded memory growth
- JSON request/response serialization via
serde - Integrated error handling with
rskit-errors - Request builder pattern for fluent API
Usage
use ;
async
Authentication and redaction
use ;
use SecretString;
// Bearer token
let auth = bearer;
// HTTP Basic
let auth = basic;
// API Key
let auth = api_key;
// Use *_secret constructors when a secret is already held as a SecretString.
let token = new;
let auth = bearer_secret;
// Auth and HttpClientConfig debug output redact credential values.
let config = new.with_auth;
assert!;
// Per-request override
let resp = client.send.await?;
Auth::header() intentionally exposes credential values only at the final request-application boundary. Do not use with_header for bearer/API-key credentials; prefer with_auth or per-request auth helpers so debug output keeps credential fields redacted.
Transport hardening
HttpClientConfig applies safe transport defaults:
- redirects are capped by
max_redirects(default: 5) - response bodies are capped by
max_response_body_bytes(default: 10 MiB) DestinationPolicyvalidates initial request URLs and redirect targets- link-local address literals and common cloud metadata endpoints are blocked by default
Use an allow-list for clients that should only call known hosts:
use ;
let config = new
.with_base_url
.with_destination_policy
.with_max_response_body_bytes;
Hostname validation happens before DNS resolution, so host allow-lists are the preferred protection for high-trust clients that must not follow arbitrary destination names.
Error Handling
All methods return AppResult<T> (alias for Result<T, AppError>). Errors are classified with appropriate ErrorCode values:
Timeoutfor request timeoutsConnectionFailedfor connection errorsUnauthorizedfor 401 responsesForbiddenfor 403 responsesNotFoundfor 404 responses- And more...
match client.get.await