mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
port multipart support
This commit is contained in:
parent
c59937784e
commit
4309d9b88c
@ -82,6 +82,7 @@ derive_more = "0.14"
|
|||||||
encoding = "0.2"
|
encoding = "0.2"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
hashbrown = "0.1.8"
|
hashbrown = "0.1.8"
|
||||||
|
httparse = "1.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mime = "0.3"
|
mime = "0.3"
|
||||||
net2 = "0.2.33"
|
net2 = "0.2.33"
|
||||||
|
@ -905,6 +905,20 @@ mod tests {
|
|||||||
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_payload_error() {
|
||||||
|
let err: PayloadError =
|
||||||
|
io::Error::new(io::ErrorKind::Other, "ParseError").into();
|
||||||
|
assert_eq!(format!("{}", err), "ParseError");
|
||||||
|
assert_eq!(format!("{}", err.cause().unwrap()), "ParseError");
|
||||||
|
|
||||||
|
let err = PayloadError::Incomplete;
|
||||||
|
assert_eq!(
|
||||||
|
format!("{}", err),
|
||||||
|
"A payload reached EOF, but is not complete."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! from {
|
macro_rules! from {
|
||||||
($from:expr => $error:pat) => {
|
($from:expr => $error:pat) => {
|
||||||
match ParseError::from($from) {
|
match ParseError::from($from) {
|
||||||
|
36
src/error.rs
36
src/error.rs
@ -143,6 +143,36 @@ impl ResponseError for ReadlinesError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A set of errors that can occur during parsing multipart streams
|
||||||
|
#[derive(Debug, Display, From)]
|
||||||
|
pub enum MultipartError {
|
||||||
|
/// Content-Type header is not found
|
||||||
|
#[display(fmt = "No Content-type header found")]
|
||||||
|
NoContentType,
|
||||||
|
/// Can not parse Content-Type header
|
||||||
|
#[display(fmt = "Can not parse Content-Type header")]
|
||||||
|
ParseContentType,
|
||||||
|
/// Multipart boundary is not found
|
||||||
|
#[display(fmt = "Multipart boundary is not found")]
|
||||||
|
Boundary,
|
||||||
|
/// Multipart stream is incomplete
|
||||||
|
#[display(fmt = "Multipart stream is incomplete")]
|
||||||
|
Incomplete,
|
||||||
|
/// Error during field parsing
|
||||||
|
#[display(fmt = "{}", _0)]
|
||||||
|
Parse(ParseError),
|
||||||
|
/// Payload error
|
||||||
|
#[display(fmt = "{}", _0)]
|
||||||
|
Payload(PayloadError),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return `BadRequest` for `MultipartError`
|
||||||
|
impl ResponseError for MultipartError {
|
||||||
|
fn error_response(&self) -> HttpResponse {
|
||||||
|
HttpResponse::new(StatusCode::BAD_REQUEST)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -172,4 +202,10 @@ mod tests {
|
|||||||
let resp: HttpResponse = ReadlinesError::EncodingError.error_response();
|
let resp: HttpResponse = ReadlinesError::EncodingError.error_response();
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_multipart_error() {
|
||||||
|
let resp: HttpResponse = MultipartError::Boundary.error_response();
|
||||||
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,12 @@ where
|
|||||||
///
|
///
|
||||||
/// Note that this function is intended to be used only for testing purpose.
|
/// Note that this function is intended to be used only for testing purpose.
|
||||||
/// This function panics on nested call.
|
/// This function panics on nested call.
|
||||||
pub fn run_on<F, I, E>(f: F) -> Result<I, E>
|
pub fn run_on<F, R>(f: F) -> R
|
||||||
where
|
where
|
||||||
F: Fn() -> Result<I, E>,
|
F: Fn() -> R,
|
||||||
{
|
{
|
||||||
RT.with(move |rt| rt.borrow_mut().block_on(lazy(f)))
|
RT.with(move |rt| rt.borrow_mut().block_on(lazy(|| Ok::<_, ()>(f()))))
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ok_service() -> impl Service<
|
pub fn ok_service() -> impl Service<
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
pub(crate) mod form;
|
pub(crate) mod form;
|
||||||
pub(crate) mod json;
|
pub(crate) mod json;
|
||||||
|
mod multipart;
|
||||||
mod path;
|
mod path;
|
||||||
pub(crate) mod payload;
|
pub(crate) mod payload;
|
||||||
mod query;
|
mod query;
|
||||||
@ -9,6 +10,7 @@ pub(crate) mod readlines;
|
|||||||
|
|
||||||
pub use self::form::{Form, FormConfig};
|
pub use self::form::{Form, FormConfig};
|
||||||
pub use self::json::{Json, JsonConfig};
|
pub use self::json::{Json, JsonConfig};
|
||||||
|
pub use self::multipart::{Multipart, MultipartItem};
|
||||||
pub use self::path::Path;
|
pub use self::path::Path;
|
||||||
pub use self::payload::{Payload, PayloadConfig};
|
pub use self::payload::{Payload, PayloadConfig};
|
||||||
pub use self::query::Query;
|
pub use self::query::Query;
|
||||||
|
1137
src/types/multipart.rs
Normal file
1137
src/types/multipart.rs
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user