chiark / gitweb /
server: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 14:59:09 +0000 (15:59 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 14:59:09 +0000 (15:59 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/server.rs

index 94fa8bcfda810c5f7a1e2f25e886af5f69814e93..3724c453c48fc76fd96078e5cdf390cc28bf6ef9 100644 (file)
@@ -13,6 +13,7 @@ pub struct Opts {
   config: config::Opts,
 }
 
+const METADATA_MAX_LEN: usize = MAX_OVERHEAD;
 
 async fn handle(
 //    context: (),
@@ -20,6 +21,7 @@ async fn handle(
     req: hyper::Request<hyper::Body>
 ) -> Result<hyper::Response<hyper::Body>, Infallible> {
 
+  let mkboundary = |b: &'_ _| format!("\n--{}", b).into_bytes();
   let (boundary, warning) = (||{
     let mut ctypes = req.headers().get_all("Content-Type").iter();
     let t = ctypes.next().ok_or_else(|| anyhow!("missing Content-Type"))?;
@@ -33,14 +35,32 @@ async fn handle(
       if t.subtype() != "form-data" { throw!(anyhow!("not /form-data"))}
       Ok::<_,AE>(())
     })();
-    Ok::<_,AE>((b.as_str().to_owned(), warning))
+    let b = mkboundary(b.as_str());
+    Ok::<_,AE>((b, warning))
   })().unwrap_or_else(|e| {
-    ("b".into(), Err(e.wrap_err("guessing boundary")))
+    (mkboundary("b"), Err(e.wrap_err("guessing boundary")))
   });
 
-  eprintln!("boundary={}", boundary);
   if let Err(w) = &warning { eprintln!("warning={}", w); }
 
+  match async {
+    let mut body = req.into_body();
+    let initial = match read_limited_bytes(METADATA_MAX_LEN, &mut body).await {
+      Ok(all) => all,
+      Err(ReadLimitedError::Truncated { sofar,.. }) => sofar,
+      Err(ReadLimitedError::Hyper(e)) => throw!(e),
+    };
+
+    eprintln!("boundary={:?} initial={:?}", boundary, initial);
+
+    Ok::<_,AE>(())
+  }.await {
+    Ok(()) => {
+    },
+    Err(e) => {
+      eprintln!("error={}", e);
+    }
+  }
 
   Ok(hyper::Response::new(hyper::Body::from("Hello World")))
 }