| Crates.io | mimic-rs |
| lib.rs | mimic-rs |
| version | 0.1.1 |
| created_at | 2026-01-02 12:11:47.15152+00 |
| updated_at | 2026-01-14 20:06:47.964897+00 |
| description | High-performance User-Agent to Sec-CH-UA Client Hints converter |
| homepage | |
| repository | https://github.com/jfuqx/mimic-rs |
| max_upload_size | |
| id | 2018459 |
| size | 60,787 |
High-performance User-Agent to Sec-CH-UA Client Hints converter for Rust.
mimic-rs parses User-Agent strings from Chromium-based browsers and generates the corresponding Sec-CH-UA (Client Hints) headers. This is useful for:
serde support for serializationAdd to your Cargo.toml:
[dependencies]
mimic-rs = "0.1"
With serde support:
[dependencies]
mimic-rs = { version = "0.1", features = ["serde"] }
use mimic_rs::ClientHints;
fn main() {
let user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 \
(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
let hints = ClientHints::from_ua(user_agent).unwrap();
println!("sec-ch-ua: {}", hints.sec_ch_ua());
println!("sec-ch-ua-mobile: {}", hints.sec_ch_ua_mobile());
println!("sec-ch-ua-platform: {}", hints.sec_ch_ua_platform());
}
Output:
sec-ch-ua: "Not A(Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
use mimic_rs::{ClientHints, Brand, Platform};
let hints = ClientHints::new(
Brand::Chrome,
120,
"120.0.6099.129",
Platform::Windows,
false,
);
println!("sec-ch-ua: {}", hints.sec_ch_ua());
println!("sec-ch-ua-full-version-list: {}", hints.sec_ch_ua_full_version_list());
use mimic_rs::ClientHints;
let ua = "Mozilla/5.0 (Linux; Android 13) Chrome/120.0.0.0 Mobile Safari/537.36";
let hints = ClientHints::from_ua(ua).unwrap();
let (sec_ch_ua, sec_ch_ua_mobile, sec_ch_ua_platform) = hints.all_headers();
| Browser | Detection Token | Brand Name |
|---|---|---|
| Chrome | Chrome/ |
Google Chrome |
| Edge | Edg/, EdgA/, EdgiOS/ |
Microsoft Edge |
| Brave | Brave |
Brave |
| Opera | OPR/, Opera/ |
Opera |
| Vivaldi | Vivaldi/ |
Vivaldi |
| Samsung Internet | SamsungBrowser/ |
Samsung Internet |
| Yandex | YaBrowser/, Yandex/ |
Yandex Browser |
| Chromium | Chromium/ |
Chromium |
ClientHintsMain struct containing parsed browser information.
from_ua(user_agent: &str) -> Result<ClientHints, ParseError> - Parse a User-Agent stringnew(brand, major_version, full_version, platform, is_mobile) - Create manuallybrand() -> Brand - Get the detected browser brandmajor_version() -> u32 - Get the major version numberfull_version() -> &str - Get the full version stringplatform() -> Platform - Get the detected platformis_mobile() -> bool - Check if mobile browsersec_ch_ua() -> String - Generate sec-ch-ua header valuesec_ch_ua_full_version_list() -> String - Generate sec-ch-ua-full-version-list headersec_ch_ua_mobile() -> &'static str - Generate sec-ch-ua-mobile header (?0 or ?1)sec_ch_ua_platform() -> String - Generate sec-ch-ua-platform headerall_headers() -> (String, &'static str, String) - Get all three main headersBrandEnum representing browser brands:
Chrome, Edge, Brave, Opera, Vivaldi, Samsung, Yandex, ChromiumPlatformEnum representing operating systems:
Windows, MacOS, Linux, Android, ChromeOS, UnknownParseErrorError types:
EmptyUserAgent - Empty input stringNotChromiumBased - Not a Chromium browserInvalidVersion - Could not parse versionChromeTokenNotFound - No Chrome/Chromium token foundThe library is optimized for speed:
#[inline] on hot pathsRun benchmarks:
cargo bench
Chromium browsers include a "greased" fake brand in the sec-ch-ua header to prevent servers from relying on specific patterns. The greased brand changes based on the major version:
, (, :, -, .8, 99, 24This library accurately replicates Chromium's greasing algorithm.
MIT License - see LICENSE for details.
Inspired by mimic (Go).