You apparently have to flush
This commit is contained in:
parent
6b39cbfd4f
commit
fe514a3066
|
@ -15,6 +15,15 @@ pub struct HTTPRequest {
|
|||
pub body: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct HTTPResponse {
|
||||
pub version: String,
|
||||
pub status_code: u16,
|
||||
pub status: String,
|
||||
pub headers: Vec<HTTPHeader>,
|
||||
pub body: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[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<tor_rtcompat::PreferredRuntime>,
|
||||
) -> Result<Vec<u8>> {
|
||||
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<u8> = 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;
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue