mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-11 12:31:25 +01:00
Update multer (#2433)
This commit is contained in:
parent
6e0955ed9b
commit
72ccde5900
6 changed files with 13 additions and 39 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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`].
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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`].
|
||||
|
|
Loading…
Reference in a new issue