Fix Content-Disposition header for non-latin characters (#1)
This commit is contained in:
parent
2e23cdecfb
commit
32fbd71d03
|
@ -1,10 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-form-data"
|
name = "actix-form-data"
|
||||||
description = "Multipart Form Data for Actix Web"
|
description = "Multipart Form Data for Actix Web"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
repository = "https://git.asonix.cloud/asonix/actix-form-data.git"
|
repository = "https://git.asonix.dog/asonix/actix-form-data.git"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["actix", "form-data", "multipart", "async"]
|
keywords = ["actix", "form-data", "multipart", "async"]
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ keywords = ["actix", "form-data", "multipart", "async"]
|
||||||
name = "form_data"
|
name = "form_data"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "0.7.0"
|
actix-web = "0.7.15"
|
||||||
bytes = "0.4.7"
|
bytes = "0.4.7"
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
futures = "0.1.21"
|
futures = "0.1.21"
|
||||||
|
|
|
@ -11,8 +11,8 @@ Add it to your dependencies.
|
||||||
# Cargo.toml
|
# Cargo.toml
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "0.7.0"
|
actix-web = "0.7.15"
|
||||||
actix-form-data = "0.3.1"
|
actix-form-data = "0.3.2"
|
||||||
```
|
```
|
||||||
|
|
||||||
Require it in your project.
|
Require it in your project.
|
||||||
|
|
|
@ -35,7 +35,6 @@ use futures::{
|
||||||
Future, Stream,
|
Future, Stream,
|
||||||
};
|
};
|
||||||
use futures_fs::FsPool;
|
use futures_fs::FsPool;
|
||||||
use http::header::CONTENT_DISPOSITION;
|
|
||||||
|
|
||||||
use super::FilenameGenerator;
|
use super::FilenameGenerator;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
@ -93,50 +92,17 @@ fn parse_multipart_name(name: String) -> Result<Vec<NamePart>, Error> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_content_disposition<S>(field: &multipart::Field<S>) -> Result<ContentDisposition, Error>
|
fn parse_content_disposition<S>(field: &multipart::Field<S>) -> ContentDisposition
|
||||||
where
|
where
|
||||||
S: Stream<Item = Bytes, Error = PayloadError>,
|
S: Stream<Item = Bytes, Error = PayloadError>,
|
||||||
{
|
{
|
||||||
let content_disposition = if let Some(cd) = field.headers().get(CONTENT_DISPOSITION) {
|
match field.content_disposition() {
|
||||||
cd
|
Some(x) => ContentDisposition {
|
||||||
} else {
|
name: x.get_name().map(|v| v.to_string()),
|
||||||
return Err(Error::ContentDisposition);
|
filename: x.get_filename().map(|v| v.to_string()),
|
||||||
};
|
},
|
||||||
|
None => ContentDisposition::empty(),
|
||||||
let content_disposition = if let Ok(cd) = content_disposition.to_str() {
|
}
|
||||||
cd
|
|
||||||
} else {
|
|
||||||
return Err(Error::ContentDisposition);
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(content_disposition
|
|
||||||
.split(';')
|
|
||||||
.skip(1)
|
|
||||||
.filter_map(|section| {
|
|
||||||
let mut parts = section.splitn(2, '=');
|
|
||||||
|
|
||||||
let key = if let Some(key) = parts.next() {
|
|
||||||
key.trim()
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let val = if let Some(val) = parts.next() {
|
|
||||||
val.trim()
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
Some((key, val.trim_matches('"')))
|
|
||||||
})
|
|
||||||
.fold(ContentDisposition::empty(), |mut acc, (key, val)| {
|
|
||||||
if key == "name" {
|
|
||||||
acc.name = Some(val.to_owned());
|
|
||||||
} else if key == "filename" {
|
|
||||||
acc.filename = Some(val.to_owned());
|
|
||||||
}
|
|
||||||
acc
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -288,10 +254,7 @@ fn handle_stream_field<S>(
|
||||||
where
|
where
|
||||||
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
|
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
|
||||||
{
|
{
|
||||||
let content_disposition = match parse_content_disposition(&field) {
|
let content_disposition = parse_content_disposition(&field);
|
||||||
Ok(cd) => cd,
|
|
||||||
Err(e) => return Box::new(result(Err(e))),
|
|
||||||
};
|
|
||||||
|
|
||||||
let name = match content_disposition.name {
|
let name = match content_disposition.name {
|
||||||
Some(name) => name,
|
Some(name) => name,
|
||||||
|
|
Loading…
Reference in a new issue