chiark / gitweb /
server: wip, mime type, generated ICE
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 10:58:13 +0000 (11:58 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 10:58:13 +0000 (11:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/server.rs

index 6d517fe73bcdb33e547dbe1ade96872c82471433..b885b9591f36b77a4a2743d94fd52961f73547a6 100644 (file)
@@ -19,7 +19,27 @@ async fn handle(
 //    addr: SocketAddr,
     _req: hyper::Request<hyper::Body>
 ) -> Result<hyper::Response<hyper::Body>, Infallible> {
-    Ok(hyper::Response::new(hyper::Body::from("Hello World")))
+
+  let (boundary, warning) = (||{
+    let mut ctypes = req.headers().get_all();
+    let t = ctypes.next().ok_or_else(|| anyhow!("missing Content-Type"))?;
+    if ctypes.next().is_soe() { throw!(anyhow!("several Content-Type")) }
+    let t: mime::Mime = t.parse().context("parse Content-Type")?;
+    if t.type_() != "multipart" { throw!(anyhow!("not multipart/")) }
+    let b = t.get_param(mime::BOUNDARY).context("missing boundary=...")?;
+    let warning = (||{
+      if t.subtype != "form-data" { throw!(anyhow("not multipart/form-data")) }
+      Ok::<_,AE>(())
+    })();
+    Ok::<_,AE>((b, warning))
+  }()).unwrap_or_else(|e| {
+    ("b", Err(e.context("guessing boundary")))
+  });
+
+  eprintln!("boundary={} warning={}", boundary, warning);
+
+
+  Ok(hyper::Response::new(hyper::Body::from("Hello World")))
 }