From 32fbd71d031b85a1cb21c85472cf66c768747a59 Mon Sep 17 00:00:00 2001 From: "Arlo (Hyena)" Date: Sat, 19 Jan 2019 14:49:26 +0000 Subject: [PATCH] Fix Content-Disposition header for non-latin characters (#1) --- Cargo.toml | 6 +++--- README.md | 4 ++-- src/upload.rs | 55 +++++++++------------------------------------------ 3 files changed, 14 insertions(+), 51 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9037d1..c0d1def 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "actix-form-data" description = "Multipart Form Data for Actix Web" -version = "0.3.1" +version = "0.3.2" license = "GPL-3.0" authors = ["asonix "] -repository = "https://git.asonix.cloud/asonix/actix-form-data.git" +repository = "https://git.asonix.dog/asonix/actix-form-data.git" readme = "README.md" keywords = ["actix", "form-data", "multipart", "async"] @@ -12,7 +12,7 @@ keywords = ["actix", "form-data", "multipart", "async"] name = "form_data" [dependencies] -actix-web = "0.7.0" +actix-web = "0.7.15" bytes = "0.4.7" failure = "0.1" futures = "0.1.21" diff --git a/README.md b/README.md index d499047..22d345c 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Add it to your dependencies. # Cargo.toml [dependencies] -actix-web = "0.7.0" -actix-form-data = "0.3.1" +actix-web = "0.7.15" +actix-form-data = "0.3.2" ``` Require it in your project. diff --git a/src/upload.rs b/src/upload.rs index 7bd90a2..e350fa7 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -35,7 +35,6 @@ use futures::{ Future, Stream, }; use futures_fs::FsPool; -use http::header::CONTENT_DISPOSITION; use super::FilenameGenerator; use error::Error; @@ -93,50 +92,17 @@ fn parse_multipart_name(name: String) -> Result, Error> { }) } -fn parse_content_disposition(field: &multipart::Field) -> Result +fn parse_content_disposition(field: &multipart::Field) -> ContentDisposition where S: Stream, { - let content_disposition = if let Some(cd) = field.headers().get(CONTENT_DISPOSITION) { - cd - } else { - return Err(Error::ContentDisposition); - }; - - 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 - })) + match field.content_disposition() { + Some(x) => ContentDisposition { + name: x.get_name().map(|v| v.to_string()), + filename: x.get_filename().map(|v| v.to_string()), + }, + None => ContentDisposition::empty(), + } } #[cfg(unix)] @@ -288,10 +254,7 @@ fn handle_stream_field( where S: Stream + 'static, { - let content_disposition = match parse_content_disposition(&field) { - Ok(cd) => cd, - Err(e) => return Box::new(result(Err(e))), - }; + let content_disposition = parse_content_disposition(&field); let name = match content_disposition.name { Some(name) => name,