Skip to content

Commit

Permalink
feat: guess mime for file
Browse files Browse the repository at this point in the history
  • Loading branch information
fMeow committed May 29, 2021
1 parent abf1cf2 commit 1f4583e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ impl FormData {
let mut filepart: mime_multipart::FilePart = filepart.clone().into();
// We leave all headers that the caller specified, except that we rewrite
// Content-Disposition.
if filepart.headers.get::<ContentType>().is_none() {
let guess = mime_guess::guess_mime_type(&filepart.path);
filepart.headers.set(ContentType(guess));
}
while filepart.headers.remove::<ContentDisposition>() {}
let filename = match filepart.path.file_name() {
Some(fname) => fname.to_string_lossy().into_owned(),
Expand Down
6 changes: 0 additions & 6 deletions tests/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ async fn multipart() {

let mut photo_headers = http::header::HeaderMap::new();
photo_headers.insert(http::header::CONTENT_TYPE, "image/gif".parse().unwrap());
photo_headers.insert(
http::header::CONTENT_DISPOSITION,
"form-data; name=\"photo\"; filename=\"make.gig\""
.parse()
.unwrap(),
);

let form = FormData {
fields: vec![
Expand Down
6 changes: 0 additions & 6 deletions tests/surf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ async fn multipart() {

let mut photo_headers = http::header::HeaderMap::new();
photo_headers.insert(http::header::CONTENT_TYPE, "image/gif".parse().unwrap());
photo_headers.insert(
http::header::CONTENT_DISPOSITION,
"form-data; name=\"photo\"; filename=\"make.gig\""
.parse()
.unwrap(),
);

let form = FormData {
fields: vec![
Expand Down

0 comments on commit 1f4583e

Please sign in to comment.