Skip to content

Commit

Permalink
chore: rename package to impit
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed Jan 13, 2025
1 parent 8dbc5a8 commit 9a48221
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 92 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "retch"
name = "impit"
version = "0.1.0"
edition = "2021"

Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# retch | browser impersonation made simple
# impit | browser impersonation made simple

Retch is a `rust` library that allows you to impersonate a browser and make requests to websites. It is built on top of `reqwest`, `rustls` and `tokio` and supports HTTP/1.1, HTTP/2, and HTTP/3.
impit is a `rust` library that allows you to impersonate a browser and make requests to websites. It is built on top of `reqwest`, `rustls` and `tokio` and supports HTTP/1.1, HTTP/2, and HTTP/3.

The library provides a simple API for making requests to websites, and it also allows you to customize the request headers, use proxies, custom timeouts and more.

```rust
use retch::retcher::Retcher;
use retch::emulation::Browser;
use impit::impit::Impit;
use impit::emulation::Browser;

#[tokio::main]
async fn main() {
let mut retcher = Retcher::builder()
let mut impit = Impit::builder()
.with_browser(Browser::Firefox)
.with_http3()
.build();

let response = retcher.get(String::from("https://example.com"), None).await;
let response = impit.get(String::from("https://example.com"), None).await;

match response {
Ok(response) => {
Expand All @@ -30,29 +30,29 @@ async fn main() {

### Other projects

If you are looking for a command-line tool that allows you to make requests to websites, check out the [`retch-cli`](https://github.com/retch-http/retch-cli/) project.
If you are looking for a command-line tool that allows you to make requests to websites, check out the [`impit-cli`](https://github.com/apify/impit-cli/) project.

If you'd prefer to use `retch` from a Node.js application, check out the [`retch-node`](https://github.com/retch-http/retch-node) repository, or download the package from npm:
If you'd prefer to use `impit` from a Node.js application, check out the [`impit-node`](https://github.com/apify/impit-node) repository, or download the package from npm:
```bash
npm install retch-http
npm install impit
```

### Usage from Rust

Technically speaking, the `retch` project is a somewhat thin wrapper around `reqwest` that provides a more ergonomic API for making requests to websites.
The real strength of `retch` is that it uses patched versions of `rustls` and other libraries that allow it to make browser-like requests.
Technically speaking, the `impit` project is a somewhat thin wrapper around `reqwest` that provides a more ergonomic API for making requests to websites.
The real strength of `impit` is that it uses patched versions of `rustls` and other libraries that allow it to make browser-like requests.

Note that if you want to use this library in your rust project, you have to add the following dependencies to your `Cargo.toml` file:
```toml
[dependencies]
retch = { git="https://github.com/retch-http/retch.git", branch="master" }
impit = { git="https://github.com/apify/impit.git", branch="master" }

[patch.crates-io]
rustls = { git="https://github.com/retch-http/rustls.git", branch="retch-patch" }
h2 = { git="https://github.com/retch-http/h2.git", branch="retch-patch" }
rustls = { git="https://github.com/apify/rustls.git", branch="impit-patch" }
h2 = { git="https://github.com/apify/h2.git", branch="impit-patch" }
```

Without the patched dependencies, the project won't build.

Note that you also have to build your project with `rustflags = "--cfg reqwest_unstable"`, otherwise, the build will also fail.
This is because `retch` uses unstable features of `reqwest` (namely `http3` support), which are not available in the stable version of the library.
This is because `impit` uses unstable features of `reqwest` (namely `http3` support), which are not available in the stable version of the library.
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<title>Redirecting...</title>
<link rel="canonical" href="retch/index.html" />
<link rel="canonical" href="impit/index.html" />
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url=retch/index.html" />
<meta http-equiv="refresh" content="0; url=impit/index.html" />
</head>
<body>
<p>Redirecting...</p>
Expand Down
8 changes: 4 additions & 4 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use retch::retcher::Retcher;
use retch::emulation::Browser;
use impit::impit::Impit;
use impit::emulation::Browser;

#[tokio::main]
async fn main() {
let mut retcher = Retcher::builder()
let mut impit = Impit::builder()
.with_browser(Browser::Firefox)
.with_http3()
.build();

let response = retcher.get(String::from("https://example.com"), None).await;
let response = impit.get(String::from("https://example.com"), None).await;

match response {
Ok(response) => {
Expand Down
58 changes: 29 additions & 29 deletions src/retcher.rs → src/impit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use url::Url;

use crate::{http3::H3Engine, http_headers::HttpHeaders, tls, request::RequestOptions, emulation::Browser};

/// Error types that can be returned by the `Retcher` struct.
/// Error types that can be returned by the [`Impit`] struct.
///
/// The `ErrorType` enum is used to represent the different types of errors that can occur when making requests.
/// The `RequestError` variant is used to wrap the `reqwest::Error` type.
Expand All @@ -23,25 +23,25 @@ pub enum ErrorType {
RequestError(reqwest::Error),
}

/// Retcher is the main struct used to make (impersonated) requests.
/// Impit is the main struct used to make (impersonated) requests.
///
/// It uses `reqwest::Client` to make requests and holds info about the impersonated browser.
///
/// To create a new `Retcher` instance, use the [`Retcher::builder()`](RetcherBuilder) method.
pub struct Retcher {
/// To create a new [`Impit`] instance, use the [`Impit::builder()`](ImpitBuilder) method.
pub struct Impit {
pub(self) base_client: reqwest::Client,
pub(self) h3_client: Option<reqwest::Client>,
h3_engine: Option<H3Engine>,
config: RetcherBuilder,
config: ImpitBuilder,
}

impl Default for Retcher {
impl Default for Impit {
fn default() -> Self {
RetcherBuilder::default().build()
ImpitBuilder::default().build()
}
}

/// Customizes the behavior of the `Retcher` struct when following redirects.
/// Customizes the behavior of the [`Impit`] struct when following redirects.
///
/// The `RedirectBehavior` enum is used to specify how the client should handle redirects.
#[derive(Debug, Clone)]
Expand All @@ -56,24 +56,24 @@ pub enum RedirectBehavior {
ManualRedirect,
}

/// A builder struct used to create a new `Retcher` instance.
/// A builder struct used to create a new [`Impit`] instance.
///
/// The builder allows setting the browser to impersonate, ignoring TLS errors, setting a proxy, and other options.
///
/// ### Example
/// ```rust
/// let retcher = Retcher::builder()
/// let mut impit = Impit::builder()
/// .with_browser(Browser::Firefox)
/// .with_ignore_tls_errors(true)
/// .with_proxy("http://localhost:8080".to_string())
/// .with_default_timeout(Duration::from_secs(10))
/// .with_http3()
/// .build();
///
/// let response = retcher.get("https://example.com".to_string(), None).await;
/// let response = impit.get("https://example.com".to_string(), None).await;
/// ```
#[derive(Debug, Clone)]
pub struct RetcherBuilder {
pub struct ImpitBuilder {
browser: Option<Browser>,
ignore_tls_errors: bool,
vanilla_fallback: bool,
Expand All @@ -83,9 +83,9 @@ pub struct RetcherBuilder {
redirect: RedirectBehavior,
}

impl Default for RetcherBuilder {
impl Default for ImpitBuilder {
fn default() -> Self {
RetcherBuilder {
ImpitBuilder {
browser: None,
ignore_tls_errors: false,
vanilla_fallback: true,
Expand All @@ -97,10 +97,10 @@ impl Default for RetcherBuilder {
}
}

impl RetcherBuilder {
impl ImpitBuilder {
/// Sets the browser to impersonate.
///
/// The `Browser` enum is used to set the HTTP headers, TLS behaviour and other markers to impersonate a specific browser.
/// The [`Browser`] enum is used to set the HTTP headers, TLS behaviour and other markers to impersonate a specific browser.
///
/// If not used, the client will use the default `reqwest` fingerprints.
pub fn with_browser(mut self, browser: Browser) -> Self {
Expand All @@ -124,7 +124,7 @@ impl RetcherBuilder {
/// Sets the proxy URL to use for requests.
///
/// Note that this proxy will be used for all the requests
/// made by the built `Retcher` instance.
/// made by the built [`Impit`] instance.
pub fn with_proxy(mut self, proxy_url: String) -> Self {
self.proxy_url = proxy_url;
self
Expand All @@ -140,7 +140,7 @@ impl RetcherBuilder {

/// Enables HTTP/3 usage for requests.
///
/// `retch` currently supports HTTP/3 negotiation via the HTTPS DNS record and the `Alt-Svc` header.
/// `impit` currently supports HTTP/3 negotiation via the HTTPS DNS record and the `Alt-Svc` header.
/// To enforce HTTP/3 usage, use the `http3_prior_knowledge` option in the `RequestOptions` struct when
/// making the request.
///
Expand All @@ -160,18 +160,18 @@ impl RetcherBuilder {
self
}

/// Builds the [`Retcher`] instance.
pub fn build(self) -> Retcher {
Retcher::new(self)
/// Builds the [`Impit`] instance.
pub fn build(self) -> Impit {
Impit::new(self)
}
}

impl Retcher {
pub fn builder() -> RetcherBuilder {
RetcherBuilder::default()
impl Impit {
pub fn builder() -> ImpitBuilder {
ImpitBuilder::default()
}

fn new_reqwest_client(config: &RetcherBuilder) -> Result<reqwest::Client, reqwest::Error> {
fn new_reqwest_client(config: &ImpitBuilder) -> Result<reqwest::Client, reqwest::Error> {
let mut client = reqwest::Client::builder();
let mut tls_config_builder = tls::TlsConfig::builder();
let mut tls_config_builder = tls_config_builder.with_browser(config.browser);
Expand Down Expand Up @@ -214,20 +214,20 @@ impl Retcher {
client.build()
}

/// Creates a new `Retcher` instance based on the options stored in the `RetcherBuilder` instance.
fn new(config: RetcherBuilder) -> Self {
/// Creates a new [`Impit`] instance based on the options stored in the [`ImpitBuilder`] instance.
fn new(config: ImpitBuilder) -> Self {
let mut h3_client: Option<reqwest::Client> = None;
let mut base_client = Self::new_reqwest_client(&config).unwrap();

if config.max_http_version == Version::HTTP_3 {
h3_client = Some(base_client);
base_client = Self::new_reqwest_client(&RetcherBuilder {
base_client = Self::new_reqwest_client(&ImpitBuilder {
max_http_version: Version::HTTP_2,
..config.clone()
}).unwrap();
}

Retcher {
Impit {
base_client,
h3_client,
config,
Expand Down
Loading

0 comments on commit 9a48221

Please sign in to comment.