Skip to content

Instantly share code, notes, and snippets.

@umgefahren
Created July 10, 2021 16:03
Show Gist options
  • Save umgefahren/7f76451eed1f703ab705079782baeb0f to your computer and use it in GitHub Desktop.
Save umgefahren/7f76451eed1f703ab705079782baeb0f to your computer and use it in GitHub Desktop.
Use hyper with Tor (Rust)
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