1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

Rework Content-Disposition parsing totally (#461)

This commit is contained in:
Gowee 2018-08-13 22:34:05 +08:00 committed by Douman
parent bf7779a9a3
commit d9c7cd96a6
4 changed files with 791 additions and 156 deletions

View File

@ -164,11 +164,7 @@ impl<C: StaticFileConfig> NamedFile<C> {
let disposition_type = C::content_disposition_map(ct.type_()); let disposition_type = C::content_disposition_map(ct.type_());
let cd = ContentDisposition { let cd = ContentDisposition {
disposition: disposition_type, disposition: disposition_type,
parameters: vec![DispositionParam::Filename( parameters: vec![DispositionParam::Filename(filename.into_owned())],
header::Charset::Ext("UTF-8".to_owned()),
None,
filename.as_bytes().to_vec(),
)],
}; };
(ct, cd) (ct, cd)
}; };
@ -991,9 +987,7 @@ mod tests {
let cd = ContentDisposition { let cd = ContentDisposition {
disposition: DispositionType::Attachment, disposition: DispositionType::Attachment,
parameters: vec![DispositionParam::Filename( parameters: vec![DispositionParam::Filename(
header::Charset::Ext("UTF-8".to_owned()), String::from("test.png")
None,
"test.png".as_bytes().to_vec(),
)], )],
}; };
let mut file = NamedFile::open("tests/test.png") let mut file = NamedFile::open("tests/test.png")

File diff suppressed because it is too large Load Diff

View File

@ -263,8 +263,10 @@ where
// From hyper v0.11.27 src/header/parsing.rs // From hyper v0.11.27 src/header/parsing.rs
/// An extended header parameter value (i.e., tagged with a character set and optionally, /// The value part of an extended parameter consisting of three parts:
/// a language), as defined in [RFC 5987](https://tools.ietf.org/html/rfc5987#section-3.2). /// the REQUIRED character set name (`charset`), the OPTIONAL language information (`language_tag`),
/// and a character sequence representing the actual value (`value`), separated by single quote
/// characters. It is defined in [RFC 5987](https://tools.ietf.org/html/rfc5987#section-3.2).
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct ExtendedValue { pub struct ExtendedValue {
/// The character set that is used to encode the `value` to a string. /// The character set that is used to encode the `value` to a string.

View File

@ -758,11 +758,11 @@ mod tests {
let cd = field.content_disposition().unwrap(); let cd = field.content_disposition().unwrap();
assert_eq!( assert_eq!(
cd.disposition, cd.disposition,
DispositionType::Ext("form-data".into()) DispositionType::FormData
); );
assert_eq!( assert_eq!(
cd.parameters[0], cd.parameters[0],
DispositionParam::Ext("name".into(), "file".into()) DispositionParam::Name("file".into())
); );
} }
assert_eq!(field.content_type().type_(), mime::TEXT); assert_eq!(field.content_type().type_(), mime::TEXT);