From a6e07c06b6ecd80ddd53cd9f2fb100b2486a8452 Mon Sep 17 00:00:00 2001 From: axon-q Date: Thu, 7 Jun 2018 12:32:49 +0000 Subject: [PATCH] move CD parsing to Content-Type parsing location --- src/multipart.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/multipart.rs b/src/multipart.rs index 9727ec0a1..a92c235a8 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -317,6 +317,13 @@ where return Ok(Async::NotReady); }; + // content disposition + // RFC 7578: 'Each part MUST contain a Content-Disposition header field + // where the disposition type is "form-data".' + let cd = ContentDisposition::from_raw( + headers.get(::http::header::CONTENT_DISPOSITION) + ).map_err(|_| MultipartError::ParseContentDisposition)?; + // content type let mut mt = mime::APPLICATION_OCTET_STREAM; if let Some(content_type) = headers.get(header::CONTENT_TYPE) { @@ -360,9 +367,10 @@ where Ok(Async::Ready(Some(MultipartItem::Field(Field::new( safety.clone(), headers, + cd, mt, field, - )?)))) + ))))) } } } @@ -377,8 +385,8 @@ impl Drop for InnerMultipart { /// A single field in a multipart stream pub struct Field { - ct: mime::Mime, cd: ContentDisposition, + ct: mime::Mime, headers: HeaderMap, inner: Rc>>, safety: Safety, @@ -389,22 +397,16 @@ where S: Stream, { fn new( - safety: Safety, headers: HeaderMap, ct: mime::Mime, + safety: Safety, headers: HeaderMap, cd: ContentDisposition, ct: mime::Mime, inner: Rc>>, - ) -> Result { - // RFC 7578: 'Each part MUST contain a Content-Disposition header field - // where the disposition type is "form-data".' - let cd = ContentDisposition::from_raw( - headers.get(::http::header::CONTENT_DISPOSITION) - ).map_err(|_| MultipartError::ParseContentDisposition)?; - - Ok(Field { - ct, + ) -> Self { + Field { cd, + ct, headers, inner, safety, - }) + } } /// Get a map of headers