arti_ureq_tor_client/
arti-ureq-tor-client.rs

1// Use your own instance of an `arti_client::TorClient` with arti-ureq to make a GET request.
2
3use anyhow::Context;
4
5const TEST_URL: &str = "https://check.torproject.org/api/ip";
6
7fn main() -> anyhow::Result<()> {
8    // Create your own instance of a Tor client.
9    let tor_client = arti_ureq::arti_client::TorClient::with_runtime(
10        arti_ureq::tor_rtcompat::PreferredRuntime::create().context("Failed to create runtime.")?,
11    )
12    .create_unbootstrapped()
13    .context("Error creating Tor Client.")?;
14
15    // Make a Connector and get ureq agent.
16    let ureq_agent = arti_ureq::Connector::with_tor_client(tor_client).agent();
17
18    // Make request.
19    let mut request = ureq_agent
20        .get(TEST_URL)
21        .call()
22        .context("Failed to make request.")?;
23
24    // Get response body.
25    let response = request
26        .body_mut()
27        .read_to_string()
28        .context("Failed to read body.")?;
29
30    // Will output if request was made using Tor.
31    println!("Response: {}", response);
32
33    Ok(())
34}