chiark / gitweb /
wip refactor body, pass content-length
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 Aug 2021 17:56:32 +0000 (18:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 Aug 2021 17:56:32 +0000 (18:56 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs

index 52c577917a432f705eb61ae67fe837ad55919551..3f2b44808fc0d4a739f9b7a3111127cd91e5d976 100644 (file)
@@ -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::<Bytes,Void>)
+      content!(
+        Bytes,
+        into_iter,
+        into,
+      ).map(Ok::<Bytes,Void>)
     )
   );
 
   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")?;