Relay all bytes from reader to writer until EOF or idle timeout. Used for HTTP responses with no explicit framing (no Content-Length, no Transfer-Encoding) where the body is delimited by connection close. An idle timeout prevents blocking when servers keep the TCP connection alive longer than expected (e.g. CDN keep-alive timers).
(reader: &mut R, writer: &mut W)
| 2316 | /// An idle timeout prevents blocking when servers keep the TCP connection |
| 2317 | /// alive longer than expected (e.g. CDN keep-alive timers). |
| 2318 | async fn relay_until_eof<R, W>(reader: &mut R, writer: &mut W) -> Result<()> |
| 2319 | where |
| 2320 | R: AsyncRead + Unpin, |
| 2321 | W: AsyncWrite + Unpin, |
| 2322 | { |
| 2323 | let mut buf = [0u8; RELAY_BUF_SIZE]; |
| 2324 | loop { |
| 2325 | match tokio::time::timeout(RELAY_EOF_IDLE_TIMEOUT, reader.read(&mut buf)).await { |
| 2326 | Ok(Ok(0)) => return Ok(()), |
| 2327 | Ok(Ok(n)) => { |
| 2328 | writer.write_all(&buf[..n]).await.into_diagnostic()?; |
| 2329 | writer.flush().await.into_diagnostic()?; |
| 2330 | } |
| 2331 | Ok(Err(e)) => return Err(miette::miette!("{e}")), |
| 2332 | Err(_) => { |
| 2333 | debug!( |
| 2334 | "relay_until_eof idle timeout after {:?}", |
| 2335 | RELAY_EOF_IDLE_TIMEOUT |
| 2336 | ); |
| 2337 | return Ok(()); |
| 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | /// Relay all bytes from reader to writer until EOF without an idle timeout. |
| 2344 | /// |
no test coverage detected