Skip to main content

rama_http_types/fingerprint/
mod.rs

1//! HTTP fingerprint implementations (JA4H, Akamai HTTP/2).
2
3mod akamai;
4#[doc(inline)]
5pub use akamai::{AkamaiH2, AkamaiH2ComputeError};
6
7mod ja4;
8#[doc(inline)]
9pub use ja4::{Ja4H, Ja4HComputeError};
10
11mod http_utils {
12    use private::HttpRequestProviderPriv;
13
14    use crate::{HeaderMap, Method, Version};
15
16    #[derive(Debug, Clone)]
17    /// Minimal input data structure which can be used
18    /// by ja4h computation functions instead of a reference
19    /// to a [`crate::Request`].
20    pub struct HttpRequestInput {
21        pub header_map: HeaderMap,
22        pub http_method: Method,
23        pub version: Version,
24    }
25
26    /// Sealed trait used by the ja4h computation functions,
27    /// to allow you to immediately compute from either a
28    /// [`crate::Request`] or a [`HttpRequestInput`] data structure.
29    pub trait HttpRequestProvider: HttpRequestProviderPriv {}
30    impl<P: HttpRequestProviderPriv> HttpRequestProvider for P {}
31
32    mod private {
33        use super::*;
34        use crate::Request;
35
36        pub trait HttpRequestProviderPriv {
37            fn http_request_input(self) -> HttpRequestInput;
38        }
39
40        impl<B> HttpRequestProviderPriv for &Request<B> {
41            fn http_request_input(self) -> HttpRequestInput {
42                HttpRequestInput {
43                    header_map: self.headers().clone(),
44                    http_method: self.method().clone(),
45                    version: self.version(),
46                }
47            }
48        }
49
50        impl HttpRequestProviderPriv for HttpRequestInput {
51            #[inline(always)]
52            fn http_request_input(self) -> HttpRequestInput {
53                self
54            }
55        }
56    }
57}
58
59#[doc(inline)]
60pub use http_utils::{HttpRequestInput, HttpRequestProvider};