Skip to content

Extend your favorite HTTP client with a Tor verification feature.

License

Notifications You must be signed in to change notification settings

Joffr3y/tor_check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 client = ureq::AgentBuilder::new()
        .proxy(ureq::Proxy::new("socks5://127.0.0.1:9050")?)
        .build()
        .tor_check()?;

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

    Ok(())
}

Troubles and error handling

The check depends on TorButton Web page result.
If you suspect a Web page update or an issue in the parsing process, you can obtain debug information with the log feature.

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

fn main() -> Result<(), Error<ureq::Error>> {
    // Enable logger output
    env_logger::builder()
        .filter_level(log::LevelFilter::Debug)
        .init();

    // Print the check result
    match ureq::Agent::new().tor_check() {
        Ok(_) => println!("Crongratulation!"),
        Err(Error::HttpClient(err)) => println!("HTTP error: {err}"),
        Err(Error::PageParsing(err)) => println!("I/O error: {err}"),
        Err(err) => println!("Danger! {err}"),
    };

    Ok(())
}

About

Extend your favorite HTTP client with a Tor verification feature.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published