pub struct HttpClient { /* private fields */ }Expand description
HTTPS client bound to product allowlist and config.
Shareable across tasks (&self): rate-limit clock uses a short-lived
Mutex around the map only; sleeps run without holding the lock.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(cfg: Config, cancel: CancelFlag) -> AppResult<Self>
pub fn new(cfg: Config, cancel: CancelFlag) -> AppResult<Self>
Build a client with rustls, default headers, and redirect allowlist.
Owned by one one-shot command. Call sites may Config::clone before passing
cfg when they still need the parent config after construction. That clone is
intentional and cheap relative to TLS/RTT/body I/O. ConcurrencyBudget is
built from cfg.max_concurrency (0 = auto).
§Errors
Returns ErrorKind::Config when the User-Agent is not a valid header value.
Returns ErrorKind::Network when the reqwest client cannot be built.
Sourcepub fn budget(&self) -> &ConcurrencyBudget
pub fn budget(&self) -> &ConcurrencyBudget
Shared concurrency budget for CPU-bound parse work.
Sourcepub fn retry_policy(&self) -> RetryConfig
pub fn retry_policy(&self) -> RetryConfig
Resolved retry policy (for doctor / tests).
Sourcepub async fn get_json(&self, url: &Url) -> AppResult<HttpResponse>
pub async fn get_json(&self, url: &Url) -> AppResult<HttpResponse>
GET expecting JSON (Accept: application/json).
§Errors
Returns ErrorKind::Network for allowlist, redirect, TLS, or body-cap failures.
Returns ErrorKind::Timeout when the wall-clock budget expires.
Returns ErrorKind::Interrupted or ErrorKind::Terminated on cancel
(kind preserved from the first CancelFlag::cancel_with).
Maps HTTP statuses via AppError::from_http_status (e.g. not-found, rate-limit).
Sourcepub async fn get_html(&self, url: &Url) -> AppResult<HttpResponse>
pub async fn get_html(&self, url: &Url) -> AppResult<HttpResponse>
Auto Trait Implementations§
impl !Freeze for HttpClient
impl !RefUnwindSafe for HttpClient
impl !UnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl UnsafeUnpin 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> 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