pub struct Host {
pub key: HostKey,
rate_limiter: Option<RateLimiter<NotKeyed, InMemoryState, DefaultClock>>,
semaphore: Semaphore,
client: Client,
stats: Mutex<HostStats>,
backoff_duration: Mutex<Duration>,
cache: DashMap<Uri, CacheableResponse>,
}Expand description
Represents a single host with its own rate limiting, concurrency control, HTTP client configuration, and request cache.
Each host maintains:
- A token bucket rate limiter using governor
- A semaphore for concurrency control
- A dedicated HTTP client with host-specific headers and cookies
- Statistics tracking for adaptive behavior
- A per-host cache to prevent duplicate requests
Fields§
§key: HostKeyThe hostname this instance manages
rate_limiter: Option<RateLimiter<NotKeyed, InMemoryState, DefaultClock>>Rate limiter using token bucket algorithm
semaphore: SemaphoreControls maximum concurrent requests to this host
client: ClientHTTP client configured for this specific host
stats: Mutex<HostStats>Request statistics and adaptive behavior tracking
backoff_duration: Mutex<Duration>Current backoff duration for adaptive rate limiting
cache: DashMap<Uri, CacheableResponse>Per-host cache to prevent duplicate requests during a single link check invocation.
Note that this cache has no direct relation to the inter-process persistable crate::CacheStatus.
Implementations§
Source§impl Host
impl Host
Sourcepub fn new(
key: HostKey,
host_config: &HostConfig,
global_config: &RateLimitConfig,
client: ReqwestClient,
) -> Self
pub fn new( key: HostKey, host_config: &HostConfig, global_config: &RateLimitConfig, client: ReqwestClient, ) -> Self
Create a new Host instance for the given hostname
Sourcefn get_cached_status(
&self,
uri: &Uri,
needs_body: bool,
) -> Option<CacheableResponse>
fn get_cached_status( &self, uri: &Uri, needs_body: bool, ) -> Option<CacheableResponse>
Check if a URI is cached and returns the cached response if it is valid
and satisfies the needs_body requirement.
fn record_cache_hit(&self)
fn record_cache_miss(&self)
Sourcefn cache_result(&self, uri: &Uri, response: CacheableResponse)
fn cache_result(&self, uri: &Uri, response: CacheableResponse)
Cache a request result
Sourcepub(crate) async fn execute_request(
&self,
request: Request,
needs_body: bool,
) -> Result<CacheableResponse>
pub(crate) async fn execute_request( &self, request: Request, needs_body: bool, ) -> Result<CacheableResponse>
pub(crate) const fn get_client(&self) -> &ReqwestClient
async fn perform_request( &self, request: Request, uri: Uri, needs_body: bool, ) -> Result<CacheableResponse>
Sourceasync fn await_backoff(&self)
async fn await_backoff(&self)
Await adaptive backoff if needed
async fn acquire_semaphore(&self) -> SemaphorePermit<'_>
fn update_backoff(&self, status: StatusCode)
fn update_stats(&self, status: StatusCode, request_time: Duration)
Sourcefn handle_rate_limit_headers(&self, response: &ReqwestResponse)
fn handle_rate_limit_headers(&self, response: &ReqwestResponse)
Parse rate limit headers from response and adjust behavior
Sourcefn handle_common_rate_limit_header_fields(&self, headers: &HeaderMap)
fn handle_common_rate_limit_header_fields(&self, headers: &HeaderMap)
Handle the common “X-RateLimit” header fields.
Sourcefn handle_retry_after_header(&self, headers: &HeaderMap)
fn handle_retry_after_header(&self, headers: &HeaderMap)
Handle the “Retry-After” header
fn increase_backoff(&self, increased_backoff: Duration)
Sourcepub(crate) fn record_persistent_cache_hit(&self)
pub(crate) fn record_persistent_cache_hit(&self)
Record a cache hit from the persistent disk cache. Cache misses are tracked internally, so we don’t expose such a method.
Sourcepub fn cache_size(&self) -> usize
pub fn cache_size(&self) -> usize
Get the current cache size (number of cached entries)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Host
impl !RefUnwindSafe for Host
impl Send for Host
impl Sync for Host
impl Unpin for Host
impl UnsafeUnpin for Host
impl !UnwindSafe for Host
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