tor_check

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?;
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()?;
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}"),
}