From: Ian Jackson Date: Sat, 1 Feb 2025 11:21:29 +0000 (+0000) Subject: ReadLimitedError: Don't demand that the stream is Unpin and Debug X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=4981096bd420e98cf27de0929cc779a6589c4223;p=hippotat.git ReadLimitedError: Don't demand that the stream is Unpin and Debug We're going to use futures::stream::unfold(). Signed-off-by: Ian Jackson --- diff --git a/client/client.rs b/client/client.rs index bebb83d..5b25ea7 100644 --- a/client/client.rs +++ b/client/client.rs @@ -163,7 +163,7 @@ fn submit_request<'r, 'c:'r, C:Hcc>( let mut resp = resp.into_body(); let max_body = c.ic.max_batch_down.sat() + MAX_OVERHEAD; let resp = read_limited_bytes( - max_body, default(), default(), &mut resp + max_body, default(), default(), Pin::new(&mut resp), ).await .discard_data().context("fetching response body")?; diff --git a/server/suser.rs b/server/suser.rs index 68cb4a4..aadcaf6 100644 --- a/server/suser.rs +++ b/server/suser.rs @@ -129,7 +129,7 @@ pub async fn run(global: Arc, ic.max_batch_up.sat(), initial, length_hint, - &mut body + Pin::new(&mut body), ).await.context("read request body")?; let (meta, mut comps) = diff --git a/server/sweb.rs b/server/sweb.rs index 69afc90..27c82e0 100644 --- a/server/sweb.rs +++ b/server/sweb.rs @@ -87,7 +87,7 @@ pub async fn handle( let mut body = req.into_body(); let initial = match read_limited_bytes( - METADATA_MAX_LEN, default(), length_hint, &mut body + METADATA_MAX_LEN, default(), length_hint, Pin::new(&mut body), ).await { Ok(all) => all, Err(ReadLimitedError::Truncated { sofar,.. }) => sofar, diff --git a/src/utils.rs b/src/utils.rs index 5dbb616..b15a308 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -55,9 +55,8 @@ pub impl io::Error { #[throws(ReadLimitedError)] pub async fn read_limited_bytes(limit: usize, initial: Box<[u8]>, capacity: usize, - stream: &mut S) -> Box<[u8]> -where S: futures::Stream> - + Debug + Unpin, + mut stream: Pin<&mut S>) -> Box<[u8]> +where S: futures::Stream>, H: std::error::Error + 'static, // we also require that the Stream is cancellation-safe {