### Build and install curl-impersonate from source Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/building_libcurl.md These commands build and install curl-impersonate from source on Linux, then verify the installation with impersonate-rs. The steps are: clone the repository, configure and build the Chrome version, install it, and run the verification example. ```bash git clone https://github.com/lexiforest/curl-impersonate.git cd curl-impersonate ``` ```bash mkdir build && cd build ../configure make chrome-build ``` ```bash sudo make chrome-install sudo ldconfig ``` ```bash cargo run --example verify_browsers ``` -------------------------------- ### Install system dependencies for curl-impersonate Source: https://github.com/ajsb85/impersonate-rs/blob/main/README.md Install the required system packages for building curl-impersonate on Debian/Ubuntu. The crate links against libcurl-impersonate, which must be installed on the system. ```bash # Example for installing curl-impersonate-chrome sudo apt install build-essential pkg-config cmake ninja-build curl autoconf automake libtool # Follow build instructions from https://github.com/lexiforest/curl-impersonate ``` -------------------------------- ### Enable mock feature for development Source: https://github.com/ajsb85/impersonate-rs/blob/main/README.md Enable the mock feature to stub FFI calls when libcurl-impersonate is not installed yet, useful for development. ```toml [dependencies] impersonate-rs = { version = "0.1.0", features = ["mock"] } ``` -------------------------------- ### Basic GET request with browser impersonation Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/quickstart.md Perform a simple GET request with browser impersonation using the Client builder and the Chrome124 browser profile. ```rust use impersonate_rs::{Client, Browser, Result}; fn main() -> Result<()> { let client = Client::builder() .impersonate(Browser::Chrome124) .build(); let response = client.get("https://tls.browserleaks.com/json").send()?; println!("{}", response.text()?); Ok(()) } ``` -------------------------------- ### Custom JA3 and Akamai fingerprints Source: https://github.com/ajsb85/impersonate-rs/blob/main/README.md Set custom JA3 and Akamai fingerprint strings for advanced users who need to rotate fingerprints dynamically or use custom signatures. The client then performs a GET request to https://example.com and prints the status code. ```rust use impersonate_rs::{Client, Result}; fn main() -> Result<()> { let client = Client::builder() // Set a custom JA3 string (TLS fingerprint) .ja3("771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0") // Set a custom Akamai string (HTTP/2 fingerprint) .akamai("1:65536,2:0,3:1000,4:6291456,6:262144|15663105|0|m,a,s,p") .build(); let response = client.get("https://example.com").send()?; println!("{}", response.status()); Ok(()) } ``` -------------------------------- ### Basic browser impersonation with Client Source: https://github.com/ajsb85/impersonate-rs/blob/main/README.md Create a client that impersonates Chrome 124 and perform a GET request to https://tls.browserleaks.com/json, printing the response body. Uses the high-level Client and RequestBuilder API similar to reqwest. ```rust use impersonate_rs::{Client, Browser, Result}; fn main() -> Result<()> { // Create a client that impersonates Chrome 124 let client = Client::builder() .impersonate(Browser::Chrome124) .build(); // Perform a GET request let response = client.get("https://tls.browserleaks.com/json").send()?; // Print the response body println!("Response: {}", response.text()?); Ok(()) } ``` -------------------------------- ### Discarding Cookies by Creating a New Session Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/cookies.md Discard cookies by dropping the current Session and creating a new one. The new session starts fresh with no cookies from the previous session. ```rust // Session 1 let session1 = Session::new(client.clone()); session1.get("...")?; // Session 2 (Fresh, no cookies from Session 1) let session2 = Session::new(client.clone()); ``` -------------------------------- ### Run CLI tool with impersonation Source: https://github.com/ajsb85/impersonate-rs/blob/main/README.md Clone the repository and run the CLI tool against a target URL with the --impersonate flag set to chrome124 for quick testing and verification. ```bash # Clone the repo git clone https://github.com/ajsb85/impersonate-rs.git cd impersonate-rs # Run against a target cargo run --bin impersonate -- https://tls.browserleaks.com/json --impersonate chrome124 ``` -------------------------------- ### Using Session for Cookie Management Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/cookies.md Create a Session with a client impersonating Chrome124, then use it to visit a page that sets a cookie and another page that automatically sends the cookie. The session holds the cookie jar in memory, and libcurl handles it internally. ```rust use impersonate_rs::{Client, Browser, Session, Result}; fn main() -> Result<()> { let client = Client::builder() .impersonate(Browser::Chrome124) .build(); // Create a session which holds a cookie jar let session = Session::new(client); // 1. Visit a page that sets a cookie session.get("https://httpbin.org/cookies/set/session_id/12345")?; // 2. Visit another page, the cookie is sent automatically let resp = session.get("https://httpbin.org/cookies")?; println!("Cookies sent: {}", resp.text()?); Ok(()) } ``` -------------------------------- ### Set proxy for client Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/quickstart.md Set a proxy for the client by chaining the .proxy() method with the proxy URL. ```rust let client = Client::builder() .impersonate(Browser::Chrome124) .proxy("http://user:pass@127.0.0.1:8080") .build(); ``` -------------------------------- ### ClientBuilder Methods Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/api.md The ClientBuilder provides methods to configure the HTTP client, including setting browser profiles, custom TLS fingerprints, and other options. ```APIDOC ## ClientBuilder Methods ### Description Methods to configure the client builder. ### Methods - `.impersonate(Browser)` - Sets the browser profile. - `.ja3(str)` - Sets a custom JA3 TLS fingerprint. - `.akamai(str)` - Sets a custom Akamai HTTP/2 fingerprint. - `.permute_extensions(bool)` - Randomize TLS extension order (default: true). - `.verify(bool)` - Verify SSL certificates (default: true). - `.timeout(Duration)` - Request timeout. - `.proxy(str)` - Proxy URL. - `.follow_redirects(bool)` - Follow HTTP 3xx redirects (default: true). ``` -------------------------------- ### Advanced fingerprinting with ja3 and akamai Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/quickstart.md For precise control over TLS (JA3) and HTTP/2 (Akamai) fingerprints, use the .ja3() and .akamai() methods on the client builder. ```rust let client = Client::builder() .ja3("771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0") .akamai("1:65536,2:0,3:1000,4:6291456,6:262144|15663105|0|m,a,s,p") .build(); ``` -------------------------------- ### Force HTTP version (planned API) Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/advanced/overview.md Shows a planned API for forcing a specific HTTP version via ClientBuilder. Not yet exposed in the public API; the comment indicates it is planned for a future release. ```rust // Not yet exposed in the public API of ClientBuilder. // Planned for future release: // .http_version(HttpVersion::V2) ``` -------------------------------- ### Add impersonate-rs dependency Source: https://github.com/ajsb85/impersonate-rs/blob/main/README.md Add the impersonate-rs crate as a dependency in your Cargo.toml to use the library. ```toml [dependencies] impersonate-rs = "0.1.0" ``` -------------------------------- ### Use impersonate-rs with Tokio via spawn_blocking Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/asyncio.md Wrap a blocking impersonate-rs request in tokio::task::spawn_blocking to use it inside an async Tokio context. The client is moved into the closure and the response text is awaited with ?? to propagate errors. ```rust use impersonate_rs::{Client, Browser}; use tokio::task; #[tokio::main] async fn main() -> Result<(), Box> { let client = Client::builder() .impersonate(Browser::Chrome124) .build(); // Spawn blocking task let response_text = task::spawn_blocking(move || { let resp = client.get("https://tls.browserleaks.com/json").send()?; resp.text() }).await??; println!("Response: {}", response_text); Ok(()) } ``` -------------------------------- ### Persist cookies with Session Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/quickstart.md Use the Session type to persist cookies across requests. Create a session with a client, then make requests that set and send cookies. ```rust use impersonate_rs::{Client, Session}; let client = Client::builder() .impersonate(Browser::Chrome124) .build(); let session = Session::new(client); // Cookies set here... session.get("https://httpbin.org/cookies/set/foo/bar")?; // ...are sent here let resp = session.get("https://httpbin.org/cookies")?; println!("{}", resp.text()?); ``` -------------------------------- ### Response Methods Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/api.md The Response provides methods to access the HTTP response status, body, and headers. ```APIDOC ## Response Methods ### Description Methods to access response data. ### Methods - `.status()` - HTTP status code (`u32`). - `.text()` - Body as `String`. - `.bytes()` - Body as `Vec`. - `.json()` - Deserialize body to struct. - `.headers()` - Response headers map. ``` -------------------------------- ### Override default headers with custom header Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/quickstart.md Override default headers by disabling them with .default_headers(false) and setting a custom header on the request. ```rust let client = Client::builder() .impersonate(Browser::Chrome124) .default_headers(false) // Disable default headers if needed .build(); let response = client.get("https://httpbin.org/headers") .header("User-Agent", "Custom Agent")? .send()?; ``` -------------------------------- ### RequestBuilder Methods Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/api.md The RequestBuilder provides methods to construct HTTP requests, including adding headers, setting bodies, and authentication. ```APIDOC ## RequestBuilder Methods ### Description Methods to build and customize HTTP requests. ### Methods - `.header(key, val)` - Add a custom header. - `.body(vec)` - Set raw body bytes. - `.json(obj)` - Serialize object to JSON body. - `.form(obj)` - Serialize object to Form URL Encoded body. - `.basic_auth(u, p)` - Set HTTP Basic Auth. ``` -------------------------------- ### Send form data and JSON payloads Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/quickstart.md Send URL-encoded forms or JSON payloads using the .form() and .json() methods on a POST request. ```rust use serde::Serialize; #[derive(Serialize)] struct Data { foo: String, } let client = Client::new(); // Form (application/x-www-form-urlencoded) client.post("https://httpbin.org/post") .form(&Data { foo: "bar".into() })? .send()?; // JSON (application/json) client.post("https://httpbin.org/post") .json(&Data { foo: "bar".into() })? .send()?; ``` -------------------------------- ### Browser Enum Source: https://github.com/ajsb85/impersonate-rs/blob/main/docs/api.md The Browser enum provides variants for selecting browser profiles, including Chrome, Safari, Firefox, Edge, and Tor versions. ```APIDOC ## Browser Enum ### Description The `Browser` enum supports a wide range of browser versions for impersonation. ### Variants - `Browser::Chrome99` - `Browser::Chrome100` ... `Browser::Chrome124` - `Browser::Chrome131Android` (Android Mobile) - `Browser::Safari15_3` - `Browser::Safari18_0` - `Browser::Safari17_2Ios` (iPhone) - `Browser::Firefox133` - `Browser::Firefox135` - `Browser::Edge101` - `Browser::Tor145` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.