mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 16:55:08 +02:00
apply standard formatting
This commit is contained in:
@ -27,11 +27,7 @@ pub struct Bytes {
|
||||
impl<'t> FieldReader<'t> for Bytes {
|
||||
type Future = LocalBoxFuture<'t, Result<Self, MultipartError>>;
|
||||
|
||||
fn read_field(
|
||||
_: &'t HttpRequest,
|
||||
mut field: Field,
|
||||
limits: &'t mut Limits,
|
||||
) -> Self::Future {
|
||||
fn read_field(_: &'t HttpRequest, mut field: Field, limits: &'t mut Limits) -> Self::Future {
|
||||
Box::pin(async move {
|
||||
let mut buf = BytesMut::with_capacity(131_072);
|
||||
|
||||
|
@ -7,13 +7,12 @@ use derive_more::{Deref, DerefMut, Display, Error};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use super::FieldErrorHandler;
|
||||
use crate::{
|
||||
form::{bytes::Bytes, FieldReader, Limits},
|
||||
Field, MultipartError,
|
||||
};
|
||||
|
||||
use super::FieldErrorHandler;
|
||||
|
||||
/// Deserialize from JSON.
|
||||
#[derive(Debug, Deref, DerefMut)]
|
||||
pub struct Json<T: DeserializeOwned>(pub T);
|
||||
|
@ -429,8 +429,7 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_options() {
|
||||
let srv =
|
||||
actix_test::start(|| App::new().route("/", web::post().to(test_options_route)));
|
||||
let srv = actix_test::start(|| App::new().route("/", web::post().to(test_options_route)));
|
||||
|
||||
let mut form = multipart::Form::default();
|
||||
form.add_text("field1", "value");
|
||||
@ -481,9 +480,7 @@ mod tests {
|
||||
field3: Text<String>,
|
||||
}
|
||||
|
||||
async fn test_field_renaming_route(
|
||||
form: MultipartForm<TestFieldRenaming>,
|
||||
) -> impl Responder {
|
||||
async fn test_field_renaming_route(form: MultipartForm<TestFieldRenaming>) -> impl Responder {
|
||||
assert_eq!(&*form.field1, "renamed");
|
||||
assert_eq!(&*form.field2, "field1");
|
||||
assert_eq!(&*form.field3, "field3");
|
||||
@ -492,9 +489,8 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_field_renaming() {
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().route("/", web::post().to(test_field_renaming_route))
|
||||
});
|
||||
let srv =
|
||||
actix_test::start(|| App::new().route("/", web::post().to(test_field_renaming_route)));
|
||||
|
||||
let mut form = multipart::Form::default();
|
||||
form.add_text("renamed", "renamed");
|
||||
@ -623,9 +619,7 @@ mod tests {
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
async fn test_upload_limits_file(
|
||||
form: MultipartForm<TestFileUploadLimits>,
|
||||
) -> impl Responder {
|
||||
async fn test_upload_limits_file(form: MultipartForm<TestFileUploadLimits>) -> impl Responder {
|
||||
assert!(form.field.size > 0);
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
@ -39,23 +39,20 @@ pub struct TempFile {
|
||||
impl<'t> FieldReader<'t> for TempFile {
|
||||
type Future = LocalBoxFuture<'t, Result<Self, MultipartError>>;
|
||||
|
||||
fn read_field(
|
||||
req: &'t HttpRequest,
|
||||
mut field: Field,
|
||||
limits: &'t mut Limits,
|
||||
) -> Self::Future {
|
||||
fn read_field(req: &'t HttpRequest, mut field: Field, limits: &'t mut Limits) -> Self::Future {
|
||||
Box::pin(async move {
|
||||
let config = TempFileConfig::from_req(req);
|
||||
let field_name = field.name().to_owned();
|
||||
let mut size = 0;
|
||||
|
||||
let file = config.create_tempfile().map_err(|err| {
|
||||
config.map_error(req, &field_name, TempFileError::FileIo(err))
|
||||
})?;
|
||||
let file = config
|
||||
.create_tempfile()
|
||||
.map_err(|err| config.map_error(req, &field_name, TempFileError::FileIo(err)))?;
|
||||
|
||||
let mut file_async = tokio::fs::File::from_std(file.reopen().map_err(|err| {
|
||||
config.map_error(req, &field_name, TempFileError::FileIo(err))
|
||||
})?);
|
||||
let mut file_async =
|
||||
tokio::fs::File::from_std(file.reopen().map_err(|err| {
|
||||
config.map_error(req, &field_name, TempFileError::FileIo(err))
|
||||
})?);
|
||||
|
||||
while let Some(chunk) = field.try_next().await? {
|
||||
limits.try_consume_limits(chunk.len(), false)?;
|
||||
@ -65,9 +62,10 @@ impl<'t> FieldReader<'t> for TempFile {
|
||||
})?;
|
||||
}
|
||||
|
||||
file_async.flush().await.map_err(|err| {
|
||||
config.map_error(req, &field_name, TempFileError::FileIo(err))
|
||||
})?;
|
||||
file_async
|
||||
.flush()
|
||||
.await
|
||||
.map_err(|err| config.map_error(req, &field_name, TempFileError::FileIo(err)))?;
|
||||
|
||||
Ok(TempFile {
|
||||
file,
|
||||
@ -131,12 +129,7 @@ impl TempFileConfig {
|
||||
.unwrap_or(&DEFAULT_CONFIG)
|
||||
}
|
||||
|
||||
fn map_error(
|
||||
&self,
|
||||
req: &HttpRequest,
|
||||
field_name: &str,
|
||||
err: TempFileError,
|
||||
) -> MultipartError {
|
||||
fn map_error(&self, req: &HttpRequest, field_name: &str, err: TempFileError) -> MultipartError {
|
||||
let source = if let Some(ref err_handler) = self.err_handler {
|
||||
(err_handler)(err, req)
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user