Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update multer #2433

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion axum-extra/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion axum-extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
22 changes: 3 additions & 19 deletions axum-extra/src/extract/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand All @@ -149,7 +134,6 @@ impl Multipart {
#[derive(Debug)]
pub struct Field {
inner: multer::Field<'static>,
headers: HeaderMap,
}

impl Stream for Field {
Expand Down Expand Up @@ -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`].
Expand Down
4 changes: 3 additions & 1 deletion axum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
18 changes: 2 additions & 16 deletions axum/src/extract/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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`].
Expand Down