chiark / gitweb /
server: wip, reorg warnings
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 16:30:34 +0000 (17:30 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 16:30:34 +0000 (17:30 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/server.rs
src/reporter.rs

index be85bb5acabb28b63901f7986a444179cf06a634..dfee81960ae90f71238441fe1b627a6d9eeab462 100644 (file)
@@ -20,30 +20,33 @@ async fn handle(
 //    addr: SocketAddr,
     req: hyper::Request<hyper::Body>
 ) -> Result<hyper::Response<hyper::Body>, Infallible> {
+  let mut warnings: Warnings = default();
 
-  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"))?;
-    if ctypes.next().is_some() { throw!(anyhow!("several Content-Type")) }
-    let t = t.to_str().context("interpret Content-Type as utf-8")?;
-    let t: mime::Mime = t.parse().context("parse Content-Type")?;
-    if t.type_() != "multipart" { throw!(anyhow!("not multipart/")) }
-    let b = mime::BOUNDARY;
-    let b = t.get_param(b).ok_or_else(|| anyhow!("missing boundary=..."))?;
-    let warning = (||{
-      if t.subtype() != "form-data" { throw!(anyhow!("not /form-data"))}
-      Ok::<_,AE>(())
-    })();
-    let b = mkboundary(b.as_str());
-    Ok::<_,AE>((b, warning))
-  })().unwrap_or_else(|e| {
-    (mkboundary("b"), Err(e.wrap_err("guessing boundary")))
-  });
+  match async {
 
-  if let Err(w) = &warning { eprintln!("warning={}", w); }
+    let mkboundary = |b: &'_ _| format!("\n--{}", b).into_bytes();
+    let boundary = match (||{
+      let mut ctypes = req.headers().get_all("Content-Type").iter();
+      let t = ctypes.next().ok_or_else(|| anyhow!("missing Content-Type"))?;
+      if ctypes.next().is_some() { throw!(anyhow!("several Content-Type")) }
+      let t = t.to_str().context("interpret Content-Type as utf-8")?;
+      let t: mime::Mime = t.parse().context("parse Content-Type")?;
+      if t.type_() != "multipart" { throw!(anyhow!("not multipart/")) }
+      let b = mime::BOUNDARY;
+      let b = t.get_param(b).ok_or_else(|| anyhow!("missing boundary=..."))?;
+      if t.subtype() != "form-data" {
+        warnings.add(&"Content-Type not /form-data")?;
+      }
+      let b = mkboundary(b.as_str());
+      Ok::<_,AE>(b)
+    })() {
+      Ok(y) => y,
+      Err(e) => {
+        warnings.add(&e.wrap_err("guessing boundary"))?;
+        mkboundary("b")
+      },
+    };
 
-  match async {
     let mut body = req.into_body();
     let initial = match read_limited_bytes(METADATA_MAX_LEN, &mut body).await {
       Ok(all) => all,
@@ -58,7 +61,9 @@ async fn handle(
     else if let Some(start) = find_iter.next() { start + boundary.len() }
     else { throw!(anyhow!("initial boundary not found")) };
 
+
 /*
+    let comp = multipart::process_component(
 
     if { 
 
@@ -77,6 +82,8 @@ initial[start..].strip_prefixstarts_with(b"\n")
     }
   }
 
+  eprintln!("warnings={:?}", &warnings);
+
   Ok(hyper::Response::new(hyper::Body::from("Hello World")))
 }
 
index 5b2093ba913979cc98cc924641a0f392e4c7da03..4f72c355bdfb86ea6cb7dcd6f39fa7f721a65527 100644 (file)
@@ -199,6 +199,7 @@ pub fn dedup_eyre_setup() {
 
 const MAX_WARNINGS: usize = 15;
 
+#[derive(Debug,Default)]
 pub struct Warnings {
   pub warnings: Vec<String>,
 }