pub struct CrawlerDetector { /* private fields */ }Expand description
Bot and crawler detector.
Implementations§
Source§impl CrawlerDetector
impl CrawlerDetector
Sourcepub async fn new(config: CrawlerConfig) -> Result<Self, String>
pub async fn new(config: CrawlerConfig) -> Result<Self, String>
Create a new crawler detector.
Sourcepub async fn verify(
&self,
user_agent: &str,
client_ip: IpAddr,
) -> CrawlerVerificationResult
pub async fn verify( &self, user_agent: &str, client_ip: IpAddr, ) -> CrawlerVerificationResult
Verify a request’s crawler status.
§Security
- Validates user_agent length to prevent ReDoS
- Applies DNS failure policy for fail-secure behavior
- Bounds stats map sizes to prevent memory exhaustion
Sourcepub fn check_bad_bot(
&self,
user_agent: &str,
) -> Option<&'static BadBotSignature>
pub fn check_bad_bot( &self, user_agent: &str, ) -> Option<&'static BadBotSignature>
Check if user agent matches a bad bot signature.
§Security
Exclusion logic is handled in code (not regex) to prevent ReDoS attacks from complex negative lookaheads.
Sourcepub fn stats(&self) -> CrawlerStatsSnapshot
pub fn stats(&self) -> CrawlerStatsSnapshot
Get statistics snapshot.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the detector is enabled.
Sourcepub fn config(&self) -> &CrawlerConfig
pub fn config(&self) -> &CrawlerConfig
Get the configuration.
Sourcepub fn should_block_bad_bots(&self) -> bool
pub fn should_block_bad_bots(&self) -> bool
Check if bad bots should be blocked.
Trait Implementations§
Source§impl CrawlerDetection for CrawlerDetector
Implement the CrawlerDetection trait for CrawlerDetector
impl CrawlerDetection for CrawlerDetector
Implement the CrawlerDetection trait for CrawlerDetector
Source§fn verify<'life0, 'life1, 'async_trait>(
&'life0 self,
user_agent: &'life1 str,
client_ip: IpAddr,
) -> Pin<Box<dyn Future<Output = CrawlerVerificationResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn verify<'life0, 'life1, 'async_trait>(
&'life0 self,
user_agent: &'life1 str,
client_ip: IpAddr,
) -> Pin<Box<dyn Future<Output = CrawlerVerificationResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Verify a request’s crawler status.
Source§fn is_enabled(&self) -> bool
fn is_enabled(&self) -> bool
Check if the detector is enabled.
Source§fn should_block_bad_bots(&self) -> bool
fn should_block_bad_bots(&self) -> bool
Check if bad bots should be blocked.
Source§fn stats(&self) -> CrawlerStatsSnapshot
fn stats(&self) -> CrawlerStatsSnapshot
Get statistics snapshot.
Auto Trait Implementations§
impl !Freeze for CrawlerDetector
impl !RefUnwindSafe for CrawlerDetector
impl Send for CrawlerDetector
impl Sync for CrawlerDetector
impl Unpin for CrawlerDetector
impl UnsafeUnpin for CrawlerDetector
impl !UnwindSafe for CrawlerDetector
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
Mutably borrows from an owned value. Read more
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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>
Converts
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>
Converts
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