Skip to content

Commit

Permalink
Incr more timeout for server request and enhance log
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Jun 16, 2024
1 parent 7f2b3e9 commit b7e6f43
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl PProxy {
return Err(Error::IncompleteHttpRequest);
}

let mut stream = tcp_connect_with_timeout(&proxy_addr, 30).await?;
let mut stream = tcp_connect_with_timeout(&proxy_addr, 60).await?;
stream.write_all(request).await?;

let mut response = Vec::new();
Expand All @@ -149,20 +149,20 @@ impl PProxy {
loop {
let mut buf = [0u8; 30000];

let Ok(Ok(n)) =
timeout(std::time::Duration::from_secs(30), stream.read(&mut buf)).await
else {
warn!("http stream read failed");
break;
};

if n == 0 {
warn!("empty response from http server");
break;
match timeout(std::time::Duration::from_secs(60), stream.read(&mut buf)).await {
Ok(Ok(0)) => {
warn!("empty response from http server");
break;
}
Ok(Ok(n)) => {
response.extend_from_slice(&buf[..n]);
}
x => {
warn!("http stream read failed {x:?}");
break;
}
}

response.extend_from_slice(&buf[..n]);

if full_length.not_parsed() {
let mut headers = [httparse::EMPTY_HEADER; 1024];
let mut resp_checker = httparse::Response::new(&mut headers);
Expand Down

0 comments on commit b7e6f43

Please sign in to comment.