ClientHints

Struct ClientHints 

Source
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

Source

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);
Source

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);
Source

pub const fn brand(&self) -> Brand

Returns the detected browser brand.

Source

pub const fn major_version(&self) -> u32

Returns the major version number.

Source

pub fn full_version(&self) -> &str

Returns the full version string.

Source

pub const fn platform(&self) -> Platform

Returns the detected platform.

Source

pub const fn is_mobile(&self) -> bool

Returns whether this is a mobile browser.

Source

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"
Source

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.

Source

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.

Source

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").

Source

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

Source§

fn clone(&self) -> ClientHints

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientHints

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ClientHints

Source§

fn eq(&self, other: &ClientHints) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ClientHints

Source§

impl StructuralPartialEq for ClientHints

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.