diff --git a/axum-extra/CHANGELOG.md b/axum-extra/CHANGELOG.md index d9070635..7120f6bc 100644 --- a/axum-extra/CHANGELOG.md +++ b/axum-extra/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning]. # Unreleased -- None. +- **change:** Update version of multer used internally for multipart ([#2433]) + +[#2433]: https://github.com/tokio-rs/axum/pull/2433 # 0.9.0 (27. November, 2023) diff --git a/axum-extra/Cargo.toml b/axum-extra/Cargo.toml index d4bb1f41..04929dad 100644 --- a/axum-extra/Cargo.toml +++ b/axum-extra/Cargo.toml @@ -55,7 +55,7 @@ axum-macros = { path = "../axum-macros", version = "0.4.0", optional = true } cookie = { package = "cookie", version = "0.18.0", features = ["percent-encode"], optional = true } form_urlencoded = { version = "1.1.0", optional = true } headers = { version = "0.4.0", optional = true } -multer = { version = "2.0.0", optional = true } +multer = { version = "3.0.0", optional = true } percent-encoding = { version = "2.1", optional = true } prost = { version = "0.12", optional = true } serde_html_form = { version = "0.2.0", optional = true } diff --git a/axum-extra/src/extract/multipart.rs b/axum-extra/src/extract/multipart.rs index 86725cab..8c78a777 100644 --- a/axum-extra/src/extract/multipart.rs +++ b/axum-extra/src/extract/multipart.rs @@ -12,7 +12,7 @@ use axum::{ use futures_util::stream::Stream; use http::{ header::{HeaderMap, CONTENT_TYPE}, - HeaderName, HeaderValue, Request, StatusCode, + Request, StatusCode, }; use std::{ error::Error, @@ -115,22 +115,7 @@ impl Multipart { .map_err(MultipartError::from_multer)?; if let Some(field) = field { - // multer still uses http 0.2 which means we cannot directly expose - // `multer::Field::headers`. Instead we have to eagerly convert the headers into http - // 1.0 - // - // When the next major version of multer is published we can remove this. - let mut headers = HeaderMap::with_capacity(field.headers().len()); - headers.extend(field.headers().into_iter().map(|(name, value)| { - let name = HeaderName::from_bytes(name.as_ref()).unwrap(); - let value = HeaderValue::from_bytes(value.as_ref()).unwrap(); - (name, value) - })); - - Ok(Some(Field { - inner: field, - headers, - })) + Ok(Some(Field { inner: field })) } else { Ok(None) } @@ -149,7 +134,6 @@ impl Multipart { #[derive(Debug)] pub struct Field { inner: multer::Field<'static>, - headers: HeaderMap, } impl Stream for Field { @@ -184,7 +168,7 @@ impl Field { /// Get a map of headers as [`HeaderMap`]. pub fn headers(&self) -> &HeaderMap { - &self.headers + self.inner.headers() } /// Get the full data of the field as [`Bytes`]. diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 679fdddd..bcfe2906 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- **change:** Update version of multer used internally for multipart ([#2433]) + +[#2433]: https://github.com/tokio-rs/axum/pull/2433 # 0.7.2 (03. December, 2023) diff --git a/axum/Cargo.toml b/axum/Cargo.toml index f8e1aac9..2bde57dd 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -55,7 +55,7 @@ axum-macros = { path = "../axum-macros", version = "0.4.0", optional = true } base64 = { version = "0.21.0", optional = true } hyper = { version = "1.0.0", optional = true } hyper-util = { version = "0.1.1", features = ["tokio", "server", "server-auto"], optional = true } -multer = { version = "2.0.0", optional = true } +multer = { version = "3.0.0", optional = true } serde_json = { version = "1.0", features = ["raw_value"], optional = true } serde_path_to_error = { version = "0.1.8", optional = true } serde_urlencoded = { version = "0.7", optional = true } diff --git a/axum/src/extract/multipart.rs b/axum/src/extract/multipart.rs index 5c7ae726..2c592ece 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -13,7 +13,7 @@ use axum_core::{ use futures_util::stream::Stream; use http::{ header::{HeaderMap, CONTENT_TYPE}, - HeaderName, HeaderValue, StatusCode, + StatusCode, }; use std::{ error::Error, @@ -90,21 +90,8 @@ impl Multipart { .map_err(MultipartError::from_multer)?; if let Some(field) = field { - // multer still uses http 0.2 which means we cannot directly expose - // `multer::Field::headers`. Instead we have to eagerly convert the headers into http - // 1.0 - // - // When the next major version of multer is published we can remove this. - let mut headers = HeaderMap::with_capacity(field.headers().len()); - headers.extend(field.headers().into_iter().map(|(name, value)| { - let name = HeaderName::from_bytes(name.as_ref()).unwrap(); - let value = HeaderValue::from_bytes(value.as_ref()).unwrap(); - (name, value) - })); - Ok(Some(Field { inner: field, - headers, _multipart: self, })) } else { @@ -117,7 +104,6 @@ impl Multipart { #[derive(Debug)] pub struct Field<'a> { inner: multer::Field<'static>, - headers: HeaderMap, // multer requires there to only be one live `multer::Field` at any point. This enforces that // statically, which multer does not do, it returns an error instead. _multipart: &'a mut Multipart, @@ -155,7 +141,7 @@ impl<'a> Field<'a> { /// Get a map of headers as [`HeaderMap`]. pub fn headers(&self) -> &HeaderMap { - &self.headers + self.inner.headers() } /// Get the full data of the field as [`Bytes`].