Created
July 10, 2021 16:03
-
-
Save umgefahren/7f76451eed1f703ab705079782baeb0f to your computer and use it in GitHub Desktop.
Use hyper with Tor (Rust)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tor_stream::TorStream; | |
use hyper::client::conn::Builder; | |
use hyper::Body; | |
use http::Request; | |
use tokio::net::TcpStream; | |
#[tokio::main] | |
async fn main() { | |
let url = "httpbin.org:80"; | |
let target_stream = TorStream::connect(url) | |
.unwrap(); | |
let (mut request_sender, connection) = Builder::new() | |
.handshake::<TcpStream, Body>(TcpStream::from_std(target_stream.into_inner()).unwrap()) | |
.await.unwrap(); | |
tokio::spawn(async move { | |
if let Err(e) = connection.await { | |
eprintln!("Error in connection: {}", e); | |
} | |
}); | |
let request = Request::builder() | |
.header("Host", "httpbin.org") | |
.method("GET") | |
.body(Body::from("")).unwrap(); | |
let response = request_sender.send_request(request).await.unwrap(); | |
println!("Response => {:?}", response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment