tor-check

Crates.iotor-check
lib.rstor-check
version0.2.2
created_at2025-01-02 11:22:22.385629+00
updated_at2025-12-16 11:35:24.159351+00
descriptionExtend your favorite HTTP client with a Tor verification feature
homepage
repositoryhttps://github.com/Joffr3y/tor_check
max_upload_size
id1501444
size55,841
Joffr3y (Joffr3y)

documentation

README

tor_check

crates.io Documentation MIT CI

Extend your favorite HTTP client with a Tor verification feature.

Usage

Configure your client to use the Tor proxy and call tor_check before any other requests.

Reqwest

The reqwest feature is required.

use tor_check::{TorCheck, TorCheckError};

#[tokio::main]
async fn main() -> Result<(), TorCheckError<reqwest::Error>> {
    let client = reqwest::Client::builder()
        .proxy(reqwest::Proxy::all("socks5://127.0.0.1:9050")?)
        .build()?
        .tor_check()
        .await?;

    // Ok, I am connected to Tor.
    client.get("https://example.com/").send().await?;

    Ok(())
}

Ureq

The ureq feature is required.

use tor_check::{TorCheck, TorCheckError};

fn main() -> Result<(), TorCheckError<ureq::Error>> {
    let config = ureq::Agent::config_builder()
        .proxy(Some(ureq::Proxy::new("socks5://127.0.0.1:9050")?))
        .build();
    let client = ureq::Agent::from(config).tor_check()?;

    // Ok, I am connected to Tor.
    client.get("https://example.com/").call()?;

    Ok(())
}

Troubles and error handling

This crate use check.torproject.org API result.

Possible errors returned.

use tor_check::{TorCheck, TorCheckError as Error};

match ureq::agent().tor_check() {
    Ok(_) => println!("Crongratulation!"),
    Err(err) if err.is_decode() => {
        eprintln!("Malformed response: {err}");
        eprintln!("Check https://check.torproject.org/api/ip");
    }
    Err(Error::HttpClient(err)) => {
        eprintln!("HTTP error: {err}");
        eprintln!("Check Tor services https://status.torproject.org/");
    }
    Err(err @ Error::YouAreNotUsingTor) => eprintln!("Danger! {err}"),
}
Commit count: 2

cargo fmt