huginn_net_http/matcher_api.rs
1//! HTTP matcher trait owned by `huginn-net-http`.
2//!
3//! Mirrors `huginn_net_tcp::matcher_api::TcpMatcher`. Any consumer that wants
4//! HTTP signature matching feeds an implementation of this trait into
5//! [`crate::HuginnNetHttp`]. The reference implementation lives in
6//! `huginn-net-db` (`HttpSignatureMatcher` and `SharedHttpSignatureMatcher`),
7//! but downstream users are free to plug their own.
8
9use crate::observable::{HttpRequestObservation, HttpResponseObservation};
10use crate::output::{Browser, WebServer};
11
12/// Result of matching an [`HttpRequestObservation`] against a database.
13#[derive(Debug, Clone)]
14pub struct HttpRequestMatch {
15 pub browser: Browser,
16 pub quality: f32,
17}
18
19/// Result of matching an [`HttpResponseObservation`] against a database.
20#[derive(Debug, Clone)]
21pub struct HttpResponseMatch {
22 pub web_server: WebServer,
23 pub quality: f32,
24}
25
26/// Result of mapping a User-Agent string against the database's UA→OS table.
27///
28/// `family` is the OS family (e.g. `"Windows"`, `"Linux"`); `flavor` is the
29/// optional sub-variant (e.g. `"7 or 8"`).
30#[derive(Debug, Clone)]
31pub struct UaOsMatch {
32 pub family: String,
33 pub flavor: Option<String>,
34}
35
36/// Pluggable HTTP signature matcher.
37///
38/// Implementations must be `Send + Sync` so they can be shared across the
39/// worker threads spawned by [`crate::HuginnNetHttp`].
40pub trait HttpMatcher: Send + Sync {
41 /// Match an HTTP request observation. Returns `None` if no candidate
42 /// signature meets the configured quality threshold.
43 fn match_http_request(&self, obs: &HttpRequestObservation) -> Option<HttpRequestMatch>;
44
45 /// Match an HTTP response observation.
46 fn match_http_response(&self, obs: &HttpResponseObservation) -> Option<HttpResponseMatch>;
47
48 /// Map a User-Agent string against the database UA→OS table.
49 fn match_user_agent(&self, ua: &str) -> Option<UaOsMatch>;
50}