/reqwest-impersonate

An easy and powerful Rust HTTP Client (Impersonate Chrome/OkHttp/Safari)

Primary LanguageRustApache License 2.0Apache-2.0

reqwest

A fork of reqwest used to impersonate the Chrome browser / OkHttp. Inspired by curl-impersonate.

This crate was intended to be an experiment to learn more about TLS and HTTP2 fingerprinting. Some parts of reqwest may not have the code needed to work when used to copy Chrome.

It is currently missing HTTP/2 PRIORITY support. (PRs to h2 are welcome)

These patches were made specifically for reqwest to work, but I would appreciate if someone took the time to PR more "proper" versions to the parent projects.

Example

Cargo.toml

reqwest = { package = "reqwest-impersonate", version = "0.11.46", default-features = false, features = [
    "boring-tls",
    "impersonate",
    "blocking",
] }

main.rs

use reqwest_impersonate as reqwest;

fn main() {
    // Build a client to mimic OkHttpAndroid13
    let client = reqwest::blocking::Client::builder()
        .impersonate(reqwest::impersonate::Impersonate::Chrome120)
        .enable_ech_grease(true)
        .permute_extensions(true)
        .cookie_store(true)
        .tls_info(true)
        .build()
        .unwrap();

    // Use the API you're already familiar with
    // https://tls.peet.ws/api/all
    // https://chat.openai.com/backend-api/models
    // https://chat.openai.com/backend-api/conversation
    // https://order.surfshark.com/api/v1/account/users?source=surfshark
    match client.get("https://tls.peet.ws/api/all").send() {
        Ok(res) => {
            println!("{}", res.text().unwrap());
        }
        Err(err) => {
            dbg!(err);
        }
    };

    match client
        .post("https://chat.openai.com/backend-api/conversation")
        .send()
    {
        Ok(res) => {
            println!("{}", res.text().unwrap());
        }
        Err(err) => {
            dbg!(err);
        }
    };

}

Original readme

crates.io Documentation MIT/Apache-2 licensed CI

An ergonomic, batteries-included HTTP Client for Rust.

  • Plain bodies, JSON, urlencoded, multipart
  • Customizable redirect policy
  • HTTP Proxies
  • HTTPS via system-native TLS (or optionally, rustls)
  • Cookie Store
  • WASM
  • Changelog

Example

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

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

And then the code:

use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resp = reqwest::get("https://httpbin.org/ip")
        .await?
        .json::<HashMap<String, String>>()
        .await?;
    println!("{:#?}", resp);
    Ok(())
}

Blocking Client

There is an optional "blocking" client API that can be enabled:

[dependencies]
reqwest = { version = "0.11", features = ["blocking", "json"] }
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resp = reqwest::blocking::get("https://httpbin.org/ip")?
        .json::<HashMap<String, String>>()?;
    println!("{:#?}", resp);
    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.