pub struct HeaderProfiler { /* private fields */ }Expand description
Header profiler for learning and detecting header anomalies.
Uses DashMap for lock-free concurrent access to per-endpoint baselines. Supports LRU eviction when max_endpoints is exceeded.
Implementations§
Source§impl HeaderProfiler
impl HeaderProfiler
Sourcepub fn with_config(max_endpoints: usize, min_samples: u64) -> Self
pub fn with_config(max_endpoints: usize, min_samples: u64) -> Self
Create a new header profiler with custom configuration.
§Arguments
max_endpoints- Maximum number of endpoints to trackmin_samples- Minimum samples before anomaly detection activates
Sourcepub fn learn(&self, endpoint: &str, headers: &[(String, String)])
pub fn learn(&self, endpoint: &str, headers: &[(String, String)])
Learn from a request’s headers, updating the baseline.
This method updates the per-endpoint baseline with the observed headers. It tracks header frequencies and value statistics (length, entropy).
§Arguments
endpoint- The endpoint path/templateheaders- Slice of (header_name, header_value) pairs
§Thread Safety
This method is thread-safe and can be called concurrently from multiple request handlers.
Sourcepub fn analyze(
&self,
endpoint: &str,
headers: &[(String, String)],
) -> HeaderAnomalyResult
pub fn analyze( &self, endpoint: &str, headers: &[(String, String)], ) -> HeaderAnomalyResult
Analyze a request’s headers against the learned baseline.
Returns a list of anomalies detected, along with a risk contribution score. Only generates anomalies if the baseline has enough samples.
§Arguments
endpoint- The endpoint path/templateheaders- Slice of (header_name, header_value) pairs
§Returns
HeaderAnomalyResult with detected anomalies and risk contribution
§Thread Safety
This method is thread-safe and can be called concurrently.
Sourcepub fn get_baseline(&self, endpoint: &str) -> Option<HeaderBaseline>
pub fn get_baseline(&self, endpoint: &str) -> Option<HeaderBaseline>
Get the learned baseline for an endpoint.
Returns a clone of the baseline for inspection/debugging.
Sourcepub fn endpoint_count(&self) -> usize
pub fn endpoint_count(&self) -> usize
Get the number of endpoints currently tracked.
Sourcepub fn max_endpoints(&self) -> usize
pub fn max_endpoints(&self) -> usize
Get the maximum endpoints this profiler can track.
Sourcepub fn min_samples(&self) -> u64
pub fn min_samples(&self) -> u64
Get the minimum samples required before anomaly detection.
Sourcepub fn stats(&self) -> HeaderProfilerStats
pub fn stats(&self) -> HeaderProfilerStats
Get statistics about the profiler state.
Trait Implementations§
Source§impl Clone for HeaderProfiler
impl Clone for HeaderProfiler
Source§impl Debug for HeaderProfiler
impl Debug for HeaderProfiler
Auto Trait Implementations§
impl Freeze for HeaderProfiler
impl !RefUnwindSafe for HeaderProfiler
impl Send for HeaderProfiler
impl Sync for HeaderProfiler
impl Unpin for HeaderProfiler
impl UnsafeUnpin for HeaderProfiler
impl !UnwindSafe for HeaderProfiler
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.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>
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