From: Ian Jackson Date: Sun, 8 Aug 2021 14:59:09 +0000 (+0100) Subject: server: wip X-Git-Tag: hippotat/1.0.0~211 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=b90b4a44ef531413b878fc1821f9a4a1cee6d528;p=hippotat.git server: wip Signed-off-by: Ian Jackson --- diff --git a/src/bin/server.rs b/src/bin/server.rs index 94fa8bc..3724c45 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -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 ) -> Result, 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"))) }