diff --git a/src/http_lib.rs b/src/http_lib.rs index 0abfc60..da4e33a 100644 --- a/src/http_lib.rs +++ b/src/http_lib.rs @@ -15,6 +15,15 @@ pub struct HTTPRequest { pub body: Option>, } +#[derive(Clone, Debug)] +pub struct HTTPResponse { + pub version: String, + pub status_code: u16, + pub status: String, + pub headers: Vec, + pub body: Option>, +} + #[derive(Clone, Copy, Debug)] pub enum HTTPMethod { Get, @@ -54,7 +63,10 @@ impl Serialize for HTTPRequest { result.append(&mut body) } - let _ = dbg!(String::from_utf8(result.clone())); + println!("{}", match String::from_utf8(result.clone()) { + Ok(v) => v, + Err(v) => format!("{}", v), + }); result } } @@ -80,13 +92,15 @@ pub async fn get_website( request: HTTPRequest, tor_client: TorClient, ) -> Result> { - let mut client_stream = tor_client.connect((address, port)).await?; - client_stream.write_all(&request.serialize()).await?; + let mut stream = tor_client.connect((address, port)).await?; + stream.write_all(&request.serialize()).await?; + stream.flush().await?; + println!("Sent request for {} to {address}", request.location); let mut response_status: Vec = Vec::new(); loop { - let response = client_stream.read_u8().await?; + let response = stream.read_u8().await?; response_status.push(dbg!(response)); if response == b'\n' { break; diff --git a/src/main.rs b/src/main.rs index 49702cd..241a2af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,12 @@ async fn main() -> Result<()> { version: "HTTP/1.1".to_string(), headers: vec![HTTPHeader { key: "Host".to_string(), - value: "example.com".to_string(), + value: "vanten-s.com".to_string(), }], body: None, }; - dbg!(get_website("example.com", 80, test_request, tor_client).await?); + dbg!(get_website("94.255.138.67", 80, test_request, tor_client).await?); Ok(()) }