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().
send queues a request; tick starts queued requests (up to
max_concurrent, honouring rate limits and retry backoff), collects the
finished ones, retries connection errors, timeouts and 5xx responses with
exponential backoff, and fills the event queue. Successful GET
responses are cached and, once stale, revalidated with If-None-Match /
If-Modified-Since.
Fields§
§cache_ttl: DurationDefault cache TTL.
max_concurrent: usizeMaximum simultaneous connections.
verbose: boolLog each dispatched request through the log crate at debug level.
default_headers: HashMap<String, String>Global headers added to every request.
Implementations§
Source§impl HttpClient
impl HttpClient
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 !Sync for HttpClient
impl Freeze for HttpClient
impl RefUnwindSafe for HttpClient
impl Send 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more