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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpClient
impl RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl UnsafeUnpin for HttpClient
impl UnwindSafe for HttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.