#websocket #http-request #request #websocket-client #ja3 #async-http

reqwest-impersonate

An intuitive and robust Rust HTTP/WebSocket Client featuring TLS/JA3/JA4/HTTP2 fingerprint impersonate

59 releases

new 0.11.91 Jul 25, 2024
0.11.86 Jun 29, 2024
0.11.67 Mar 21, 2024
0.11.47 Dec 29, 2023
0.11.30 Nov 11, 2023

#38 in HTTP client

Download history 236/week @ 2024-04-04 1285/week @ 2024-04-11 309/week @ 2024-04-18 1242/week @ 2024-04-25 1068/week @ 2024-05-02 964/week @ 2024-05-09 540/week @ 2024-05-16 1109/week @ 2024-05-23 685/week @ 2024-05-30 56/week @ 2024-06-06 60/week @ 2024-06-13 425/week @ 2024-06-20 1151/week @ 2024-06-27 366/week @ 2024-07-04 689/week @ 2024-07-11 702/week @ 2024-07-18

3,137 downloads per month
Used in 2 crates

MIT/Apache

735KB
15K SLoC

reqwest-impersonate

crates.io MIT/Apache-2 licensed CI

An intuitive and robust Rust HTTP/WebSocket Client featuring TLS/JA3/JA4/HTTP2 fingerprint impersonate

  • Impersonate Chrome / Safari / Edge / OkHttp
  • Plain bodies, JSON, urlencoded, multipart
  • Customizable redirect policy
  • HTTP Proxies
  • HTTPS via BoringSSL
  • WebSocket
  • Cookie Store
  • WASM
  • Changelog

Example

This asynchronous example uses Tokio and enables some optional features, so your Cargo.toml could look like this:

[dependencies]
tokio = { version = "1", features = ["full"] }
reqwest_impersonate = "0.11"

Or WebSocket:

[dependencies]
tokio = { version = "1", features = ["full"] }
reqwest_impersonate = { version = "0.11", features = ["websocket"] }

And then the code:

use std::error::Error;
use reqwest_impersonate as reqwest;
use reqwest::impersonate::Impersonate;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Build a client to mimic Chrome123
    let client = reqwest::Client::builder()
        .impersonate(Impersonate::Chrome123)
        .enable_ech_grease()
        .permute_extensions()
        .cookie_store(true)
        .build()?;

    // Use the API you're already familiar with
    let resp = client.get("https://tls.peet.ws/api/all").send().await?;
    println!("{}", resp.text().await?);

    Ok(())
}

And then the websocket code:

use reqwest_impersonate as reqwest;
use std::error::Error;
use tungstenite::Message;

use futures_util::{SinkExt, StreamExt, TryStreamExt};
use reqwest::{impersonate::Impersonate, Client};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let websocket = Client::builder()
        .impersonate_websocket(Impersonate::Chrome120)
        .build()?
        .get("wss://echo.websocket.org")
        .upgrade()
        .send()
        .await?
        .into_websocket()
        .await?;

    let (mut tx, mut rx) = websocket.split();

    tokio::spawn(async move {
        for i in 1..11 {
            tx.send(Message::Text(format!("Hello, World! #{i}")))
                .await
                .unwrap();
        }
    });

    while let Some(message) = rx.try_next().await? {
        match message {
            Message::Text(text) => println!("received: {text}"),
            _ => {}
        }
    }

    Ok(())
}

Requirements

On Linux:

  • OpenSSL with headers. See https://docs.rs/openssl for supported versions and more details. Alternatively you can enable the native-tls-vendored feature to compile a copy of OpenSSL.

On Windows and macOS:

  • Nothing.

Reqwest uses rust-native-tls, which will use the operating system TLS framework if available, meaning Windows and macOS. On Linux, it will use OpenSSL 1.1.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Sponsors

Capsolver Capsolver.com is an AI-powered service that specializes in solving various types of captchas automatically. It supports captchas such as reCAPTCHA V2, reCAPTCHA V3, hCaptcha, FunCaptcha, DataDome, AWS Captcha, Geetest, and Cloudflare Captcha / Challenge 5s, Imperva / Incapsula, among others. For developers, Capsolver offers API integration options detailed in their documentation, facilitating the integration of captcha solving into applications. They also provide browser extensions for Chrome and Firefox, making it easy to use their service directly within a browser. Different pricing packages are available to accommodate varying needs, ensuring flexibility for users.

Dependencies

~2–26MB
~543K SLoC