diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 75c09ad5..69b21b9d 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -53,7 +53,7 @@ tokio-tungstenite = { optional = true, version = "0.16" } [dev-dependencies] futures = "0.3" -reqwest = { version = "0.11", default-features = false, features = ["json", "stream"] } +reqwest = { version = "0.11", default-features = false, features = ["json", "stream", "multipart"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tokio = { version = "1.6.1", features = ["macros", "rt", "rt-multi-thread", "net", "test-util"] } diff --git a/axum/src/extract/multipart.rs b/axum/src/extract/multipart.rs index c3366ee0..d9bad33e 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -8,14 +8,13 @@ use crate::BoxError; use async_trait::async_trait; use futures_util::stream::Stream; use http::header::{HeaderMap, CONTENT_TYPE}; -use mime::Mime; use std::{ fmt, pin::Pin, task::{Context, Poll}, }; -/// Extractor that parses `multipart/form-data` requests commonly used with file uploads. +/// Extractor that parses `multipart/form-data` requests (commonly used with file uploads). /// /// # Example /// @@ -42,7 +41,7 @@ use std::{ /// # }; /// ``` /// -/// For security reasons its recommended to combine this with +/// For security reasons it's recommended to combine this with /// [`ContentLengthLimit`](super::ContentLengthLimit) to limit the size of the request payload. #[derive(Debug)] pub struct Multipart { @@ -120,9 +119,9 @@ impl<'a> Field<'a> { self.inner.file_name() } - /// Get the content type of the field. - pub fn content_type(&self) -> Option<&Mime> { - self.inner.content_type() + /// Get the [content type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) of the field. + pub fn content_type(&self) -> Option<&str> { + self.inner.content_type().map(|m| m.as_ref()) } /// Get a map of headers as [`HeaderMap`]. @@ -191,3 +190,40 @@ define_rejection! { /// missing or invalid. pub struct InvalidBoundary; } + +#[cfg(test)] +mod tests { + use super::*; + use crate::{response::IntoResponse, routing::post, test_helpers::*, Router}; + + #[tokio::test] + async fn content_type_with_encoding() { + const BYTES: &[u8] = "