chiark / gitweb /
server: boundary_finder plumbing
[hippotat.git] / src / bin / server.rs
index e7daf489c53f929bb0d9f3c60b02d7410204136a..d8bd514d893e939fe4f60e9fa7aeeee55373877a 100644 (file)
@@ -32,6 +32,7 @@ struct WebRequest {
   initial_remaining: usize,
   length_hint: usize,
   body: hyper::body::Body,
+  boundary_finder: multipart::BoundaryFinder,
   reply_to: tokio::sync::oneshot::Sender<WebResponse>,
   warnings: Warnings,
 }
@@ -107,11 +108,11 @@ async fn handle(
       Err(ReadLimitedError::Hyper(e)) => throw!(e),
     };
 
-    let finder = memmem::Finder::new(&boundary);
-    let mut find_iter = finder.find_iter(&initial);
+    let boundary_finder = memmem::Finder::new(&boundary);
+    let mut boundary_iter = boundary_finder.find_iter(&initial);
 
     let start = if initial.starts_with(&boundary[1..]) { boundary.len()-1 }
-    else if let Some(start) = find_iter.next() { start + boundary.len() }
+    else if let Some(start) = boundary_iter.next() { start + boundary.len() }
     else { throw!(anyhow!("initial boundary not found")) };
 
     let comp = multipart::process_component
@@ -186,6 +187,7 @@ async fn handle(
       initial,
       initial_remaining,
       length_hint,
+      boundary_finder: boundary_finder.into_owned(),
       body,
       warnings: mem::take(&mut warnings),
       reply_to
@@ -213,7 +215,7 @@ async fn handle(
 }
 
 #[allow(unused_variables)] // xxx
-async fn run_client(_ic: Arc<InstanceConfig>,
+async fn run_client(ic: Arc<InstanceConfig>,
                     mut web: mpsc::Receiver<WebRequest>)
                     -> Result<Void, AE>
 {
@@ -257,13 +259,14 @@ async fn run_client(_ic: Arc<InstanceConfig>,
       {
         let WebRequest {
           initial, initial_remaining, length_hint, mut body,
+          boundary_finder,
           reply_to, warnings,
         } = req.ok_or_else(|| anyhow!("webservers all shut down!"))?;
 
         match async {
 
           let whole_request = read_limited_bytes(
-            usize::MAX /* xxx */,
+            ic.max_batch_up.sat(),
             initial,
             length_hint,
             &mut body