pub struct ClientHints { /* private fields */ }Expand description
Client Hints generated from a User-Agent string.
This struct contains all the information needed to construct Sec-CH-UA headers for HTTP requests.
Implementations§
Source§impl ClientHints
impl ClientHints
Sourcepub fn from_ua(user_agent: &str) -> Result<Self, ParseError>
pub fn from_ua(user_agent: &str) -> Result<Self, ParseError>
Parse a User-Agent string and generate corresponding Client Hints.
§Arguments
user_agent- The User-Agent string to parse
§Returns
Returns Ok(ClientHints) if parsing succeeds, or Err(ParseError) if
the User-Agent string cannot be parsed or is not from a Chromium-based browser.
§Example
use mimic_rs::ClientHints;
let ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36";
let hints = ClientHints::from_ua(ua).unwrap();
assert_eq!(hints.major_version(), 120);Sourcepub fn new(
brand: Brand,
major_version: u32,
full_version: impl Into<String>,
platform: Platform,
is_mobile: bool,
) -> Self
pub fn new( brand: Brand, major_version: u32, full_version: impl Into<String>, platform: Platform, is_mobile: bool, ) -> Self
Create ClientHints with explicit values.
Use this when you already know the browser details and don’t need to parse a UA string.
§Example
use mimic_rs::{ClientHints, Brand, Platform};
let hints = ClientHints::new(Brand::Chrome, 120, "120.0.0.0", Platform::Windows, false);Sourcepub const fn major_version(&self) -> u32
pub const fn major_version(&self) -> u32
Returns the major version number.
Sourcepub fn full_version(&self) -> &str
pub fn full_version(&self) -> &str
Returns the full version string.
Sourcepub fn sec_ch_ua(&self) -> String
pub fn sec_ch_ua(&self) -> String
Generate the sec-ch-ua header value.
This includes the greased brand, Chromium brand, and the actual browser brand in a randomized order based on the version number.
§Example
use mimic_rs::ClientHints;
let ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36";
let hints = ClientHints::from_ua(ua).unwrap();
let sec_ch_ua = hints.sec_ch_ua();
// Output: "Not A(Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"Sourcepub fn sec_ch_ua_full_version_list(&self) -> String
pub fn sec_ch_ua_full_version_list(&self) -> String
Generate the sec-ch-ua-full-version-list header value.
Similar to sec_ch_ua() but uses the full version string instead of just the major version.
Sourcepub const fn sec_ch_ua_mobile(&self) -> &'static str
pub const fn sec_ch_ua_mobile(&self) -> &'static str
Generate the sec-ch-ua-mobile header value.
Returns ?1 for mobile browsers, ?0 for desktop browsers.
Sourcepub fn sec_ch_ua_platform(&self) -> String
pub fn sec_ch_ua_platform(&self) -> String
Generate the sec-ch-ua-platform header value.
Returns the platform name in quotes (e.g., "Windows").
Sourcepub fn all_headers(&self) -> (String, &'static str, String)
pub fn all_headers(&self) -> (String, &'static str, String)
Generate all standard Client Hints headers.
Returns a tuple of (sec-ch-ua, sec-ch-ua-mobile, sec-ch-ua-platform).
Trait Implementations§
Source§impl Clone for ClientHints
impl Clone for ClientHints
Source§fn clone(&self) -> ClientHints
fn clone(&self) -> ClientHints
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more