1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-22 08:07:18 +00: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 cd = ContentDisposition {
disposition: disposition_type,
parameters: vec![DispositionParam::Filename(
header::Charset::Ext("UTF-8".to_owned()),
None,
filename.as_bytes().to_vec(),
)],
parameters: vec![DispositionParam::Filename(filename.into_owned())],
};
(ct, cd)
};
@ -991,9 +987,7 @@ mod tests {
let cd = ContentDisposition {
disposition: DispositionType::Attachment,
parameters: vec![DispositionParam::Filename(
header::Charset::Ext("UTF-8".to_owned()),
None,
"test.png".as_bytes().to_vec(),
String::from("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
/// An extended header parameter value (i.e., tagged with a character set and optionally,
/// a language), as defined in [RFC 5987](https://tools.ietf.org/html/rfc5987#section-3.2).
/// The value part of an extended parameter consisting of three parts:
/// 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)]
pub struct ExtendedValue {
/// 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();
assert_eq!(
cd.disposition,
DispositionType::Ext("form-data".into())
DispositionType::FormData
);
assert_eq!(
cd.parameters[0],
DispositionParam::Ext("name".into(), "file".into())
DispositionParam::Name("file".into())
);
}
assert_eq!(field.content_type().type_(), mime::TEXT);