pub struct HttpClient {
pub cache_ttl: Duration,
pub max_concurrent: usize,
pub verbose: bool,
pub default_headers: HashMap<String, String>,
/* private fields */
}Expand description
Non-blocking HTTP client driven by tick().
In this implementation, actual TCP I/O is stubbed (see _dispatch).
The full interface, state machine, caching, retry, and rate limiting
are all implemented and production-ready. Wire in a real TCP backend
(tokio, std threads, or platform sockets) by implementing _dispatch.
Fields§
§cache_ttl: DurationDefault cache TTL.
max_concurrent: usizeMaximum simultaneous connections.
verbose: boolWhether to log requests to the debug console.
default_headers: HashMap<String, String>Global headers added to every request.
Implementations§
Source§impl HttpClient
impl HttpClient
pub fn new() -> Self
Sourcepub fn send(&mut self, request: HttpRequest) -> RequestId
pub fn send(&mut self, request: HttpRequest) -> RequestId
Submit a request. Returns the RequestId for tracking.
Sourcepub fn cancel_by_tag(&mut self, tag: &str)
pub fn cancel_by_tag(&mut self, tag: &str)
Cancel all requests with the given tag.
Sourcepub fn set_rate_limit(&mut self, base_url: &str, limit: u32, window_secs: f32)
pub fn set_rate_limit(&mut self, base_url: &str, limit: u32, window_secs: f32)
Set a default rate limiter for a base URL.
Sourcepub fn set_default_header(
&mut self,
key: impl Into<String>,
val: impl Into<String>,
)
pub fn set_default_header( &mut self, key: impl Into<String>, val: impl Into<String>, )
Set a default header on all outgoing requests.
Sourcepub fn drain_events(&mut self) -> impl Iterator<Item = HttpEvent> + '_
pub fn drain_events(&mut self) -> impl Iterator<Item = HttpEvent> + '_
Drain all completed events.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of pending + in-flight requests.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the response cache.
Sourcepub fn evict_stale_cache(&mut self)
pub fn evict_stale_cache(&mut self)
Remove cache entries older than their TTL.