From ff07ec217de7ead5f497b05fa1026aaf630978bf Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 8 Aug 2021 11:58:13 +0100 Subject: [PATCH] server: wip, mime type, generated ICE Signed-off-by: Ian Jackson --- src/bin/server.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 6d517fe..b885b95 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -19,7 +19,27 @@ async fn handle( // addr: SocketAddr, _req: hyper::Request ) -> Result, 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"))) } -- 2.30.2