diff --git a/src/field.rs b/src/field.rs index 14f7681..03a3c6e 100644 --- a/src/field.rs +++ b/src/field.rs @@ -206,7 +206,7 @@ impl<'r> Field<'r> { #[cfg(feature = "json")] #[cfg_attr(nightly, doc(cfg(feature = "json")))] pub async fn json(self) -> crate::Result { - serde_json::from_slice(&self.bytes().await?).map_err(crate::Error::DecodeJson) + serde_json::from_slice(&self.bytes().await?).map_err(Error::DecodeJson) } /// Get the full field data as text. @@ -342,7 +342,7 @@ impl Stream for Field<'_> { state.curr_field_size_counter += bytes.len() as u64; if state.curr_field_size_counter > state.curr_field_size_limit { - return Poll::Ready(Some(Err(crate::Error::FieldSizeExceeded { + return Poll::Ready(Some(Err(Error::FieldSizeExceeded { limit: state.curr_field_size_limit, field_name: state.curr_field_name.clone(), }))); diff --git a/src/lib.rs b/src/lib.rs index d480221..3a1e04e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,15 +169,15 @@ pub fn parse_boundary>(content_type: T) -> Result { let m = content_type .as_ref() .parse::() - .map_err(crate::Error::DecodeContentType)?; + .map_err(Error::DecodeContentType)?; if !(m.type_() == mime::MULTIPART && m.subtype() == mime::FORM_DATA) { - return Err(crate::Error::NoMultipart); + return Err(Error::NoMultipart); } m.get_param(mime::BOUNDARY) .map(|name| name.as_str().to_owned()) - .ok_or(crate::Error::NoBoundary) + .ok_or(Error::NoBoundary) } #[cfg(test)] diff --git a/src/multipart.rs b/src/multipart.rs index 773c710..0a9989d 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -123,7 +123,7 @@ impl<'r> Multipart<'r> { { let stream = stream .map_ok(|b| b.into()) - .map_err(|err| crate::Error::StreamReadFailed(err.into())); + .map_err(|err| Error::StreamReadFailed(err.into())); Multipart { state: Arc::new(Mutex::new(MultipartState { @@ -261,7 +261,7 @@ impl<'r> Multipart<'r> { None => { state.buffer.poll_stream(cx)?; if state.buffer.eof { - return Poll::Ready(Err(crate::Error::IncompleteStream)); + return Poll::Ready(Err(Error::IncompleteStream)); } } } @@ -277,7 +277,7 @@ impl<'r> Multipart<'r> { state.curr_field_size_counter += bytes.len() as u64; if state.curr_field_size_counter > state.curr_field_size_limit { - return Poll::Ready(Err(crate::Error::FieldSizeExceeded { + return Poll::Ready(Err(Error::FieldSizeExceeded { limit: state.curr_field_size_limit, field_name: state.curr_field_name.clone(), })); @@ -303,7 +303,7 @@ impl<'r> Multipart<'r> { Some(bytes) => bytes, None => { return if state.buffer.eof { - Poll::Ready(Err(crate::Error::IncompleteStream)) + Poll::Ready(Err(Error::IncompleteStream)) } else { Poll::Pending }; @@ -313,7 +313,7 @@ impl<'r> Multipart<'r> { if &boundary_bytes[..] == format!("{}{}", constants::BOUNDARY_EXT, boundary).as_bytes() { state.stage = StreamingStage::DeterminingBoundaryType; } else { - return Poll::Ready(Err(crate::Error::IncompleteStream)); + return Poll::Ready(Err(Error::IncompleteStream)); } } @@ -323,7 +323,7 @@ impl<'r> Multipart<'r> { Some(bytes) => bytes, None => { return if state.buffer.eof { - Poll::Ready(Err(crate::Error::IncompleteStream)) + Poll::Ready(Err(Error::IncompleteStream)) } else { Poll::Pending }; @@ -341,7 +341,7 @@ impl<'r> Multipart<'r> { if state.stage == StreamingStage::ReadingTransportPadding { if !state.buffer.advance_past_transport_padding() { return if state.buffer.eof { - Poll::Ready(Err(crate::Error::IncompleteStream)) + Poll::Ready(Err(Error::IncompleteStream)) } else { Poll::Pending }; @@ -352,7 +352,7 @@ impl<'r> Multipart<'r> { Some(bytes) => bytes, None => { return if state.buffer.eof { - Poll::Ready(Err(crate::Error::IncompleteStream)) + Poll::Ready(Err(Error::IncompleteStream)) } else { Poll::Pending }; @@ -362,7 +362,7 @@ impl<'r> Multipart<'r> { if &crlf_bytes[..] == constants::CRLF.as_bytes() { state.stage = StreamingStage::ReadingFieldHeaders; } else { - return Poll::Ready(Err(crate::Error::IncompleteStream)); + return Poll::Ready(Err(Error::IncompleteStream)); } } @@ -371,7 +371,7 @@ impl<'r> Multipart<'r> { Some(bytes) => bytes, None => { return if state.buffer.eof { - return Poll::Ready(Err(crate::Error::IncompleteStream)); + return Poll::Ready(Err(Error::IncompleteStream)); } else { Poll::Pending }; @@ -380,20 +380,19 @@ impl<'r> Multipart<'r> { let mut headers = [httparse::EMPTY_HEADER; constants::MAX_HEADERS]; - let headers = - match httparse::parse_headers(&header_bytes, &mut headers).map_err(crate::Error::ReadHeaderFailed)? { - httparse::Status::Complete((_, raw_headers)) => { - match helpers::convert_raw_headers_to_header_map(raw_headers) { - Ok(headers) => headers, - Err(err) => { - return Poll::Ready(Err(err)); - } + let headers = match httparse::parse_headers(&header_bytes, &mut headers).map_err(Error::ReadHeaderFailed)? { + httparse::Status::Complete((_, raw_headers)) => { + match helpers::convert_raw_headers_to_header_map(raw_headers) { + Ok(headers) => headers, + Err(err) => { + return Poll::Ready(Err(err)); } } - httparse::Status::Partial => { - return Poll::Ready(Err(crate::Error::IncompleteHeaders)); - } - }; + } + httparse::Status::Partial => { + return Poll::Ready(Err(Error::IncompleteHeaders)); + } + }; state.stage = StreamingStage::ReadingFieldData; @@ -412,7 +411,7 @@ impl<'r> Multipart<'r> { let field_name = content_disposition.field_name.as_deref(); if !state.constraints.is_it_allowed(field_name) { - return Poll::Ready(Err(crate::Error::UnknownField { + return Poll::Ready(Err(Error::UnknownField { field_name: field_name.map(str::to_owned), })); }