From: Ian Jackson Date: Sun, 1 Aug 2021 17:56:32 +0000 (+0100) Subject: wip refactor body, pass content-length X-Git-Tag: hippotat/1.0.0~398 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=f7795a6563dc12298a521cb04b5ee8ad90eb108e;p=hippotat.git wip refactor body, pass content-length Signed-off-by: Ian Jackson --- diff --git a/src/bin/client.rs b/src/bin/client.rs index 52c5779..3f2b448 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -69,31 +69,44 @@ fn submit_request<'r, 'c:'r, C:HCC>( ); macro_rules! content { { - $out:ty + $out:ty, + $iter:ident, + $into:ident, } => { itertools::chain![ array::IntoIter::new([ - prefix1.into(), - prefix2.into(), + prefix1.$into(), + prefix2.$into(), ]).take( if upbound.is_empty() { 1 } else { 2 } ), Itertools::intersperse( - upbound.into_iter().map(|u| { let out: $out = u.into(); out }), - SLIP_END_SLICE.into() + upbound.$iter().map(|u| { let out: $out = u.$into(); out }), + SLIP_END_SLICE.$into() ), - [ suffix.into() ], + [ suffix.$into() ], ] }} + let body_len: usize = content!( + &[u8], + iter, + as_ref, + ).map(|b| b.len()).sum(); + let body = hyper::body::Body::wrap_stream( futures::stream::iter( - content!( Bytes ).map(Ok::) + content!( + Bytes, + into_iter, + into, + ).map(Ok::) ) ); let req = hyper::Request::post(&c.ic.url) .header("Content-Type", r#"multipart/form-data; boundary="b""#) + .header("Content-Length", body_len) .body(body) .context("construct request")?;