From: Ian Jackson Date: Sun, 15 Aug 2021 17:51:40 +0000 (+0100) Subject: multipart: process_boundary: Rename, and better docs X-Git-Tag: hippotat/1.0.0~172 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=hippotat.git;a=commitdiff_plain;h=ccec56b580239af5134e5804606507339666ca4d multipart: process_boundary: Rename, and better docs Signed-off-by: Ian Jackson --- diff --git a/src/bin/server.rs b/src/bin/server.rs index d8bd514..1fd6695 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -115,7 +115,7 @@ async fn handle( else if let Some(start) = boundary_iter.next() { start + boundary.len() } else { throw!(anyhow!("initial boundary not found")) }; - let comp = multipart::process_component + let comp = multipart::process_boundary (&mut warnings, &initial[start..], PartName::m)? .ok_or_else(|| anyhow!(r#"no "m" component"#))?; @@ -123,7 +123,7 @@ async fn handle( r#"first multipart component must be name="m""# )) } - let mut meta = MetadataFieldIterator::new(comp.payload_start); + let mut meta = MetadataFieldIterator::new(comp.payload); let client: ClientName = meta.need_parse().context("client addr")?; diff --git a/src/multipart.rs b/src/multipart.rs index b858039..b076458 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -7,7 +7,7 @@ use crate::prelude::*; #[derive(Debug)] pub struct Component<'b> { pub name: PartName, - pub payload_start: &'b [u8], + pub payload: &'b [u8], } #[derive(Debug)] @@ -18,9 +18,13 @@ pub enum PartName { m, d, Other } pub type BoundaryFinder = memchr::memmem::Finder<'static>; #[throws(AE)] -pub fn process_component<'b>(warnings: &mut Warnings, - after_leader: &'b [u8], expected: PartName) - -> Option> { +/// Processes the start of a component (or terminating boundary). +/// +/// Returned payload is only the start of the payload; the next +/// boundary has not been identified. +pub fn process_boundary<'b>(warnings: &mut Warnings, + after_leader: &'b [u8], expected: PartName) + -> Option> { let rhs = after_leader; let mut rhs = if let Some(rhs) = rhs.strip_prefix(b"\r\n") { rhs } @@ -73,7 +77,7 @@ pub fn process_component<'b>(warnings: &mut Warnings, }; } - Some(Component { name: part_name.unwrap_or(expected), payload_start: rhs }) + Some(Component { name: part_name.unwrap_or(expected), payload: rhs }) } pub struct MetadataFieldIterator<'b> {