1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-26 06:57:43 +02:00

apply standard formatting

This commit is contained in:
Rob Ede
2023-07-17 02:38:12 +01:00
parent 60c76c5e10
commit 79a38e0628
138 changed files with 916 additions and 1180 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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()
}

View File

@ -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 {

View File

@ -17,5 +17,7 @@ mod server;
pub mod form;
pub use self::error::MultipartError;
pub use self::server::{Field, Multipart};
pub use self::{
error::MultipartError,
server::{Field, Multipart},
};

View File

@ -161,8 +161,8 @@ impl InnerMultipart {
for h in hdrs {
let name =
HeaderName::try_from(h.name).map_err(|_| ParseError::Header)?;
let value = HeaderValue::try_from(h.value)
.map_err(|_| ParseError::Header)?;
let value =
HeaderValue::try_from(h.value).map_err(|_| ParseError::Header)?;
headers.append(name, value);
}
@ -222,8 +222,7 @@ impl InnerMultipart {
if chunk.len() < boundary.len() {
continue;
}
if &chunk[..2] == b"--" && &chunk[2..chunk.len() - 2] == boundary.as_bytes()
{
if &chunk[..2] == b"--" && &chunk[2..chunk.len() - 2] == boundary.as_bytes() {
break;
} else {
if chunk.len() < boundary.len() + 2 {
@ -268,9 +267,7 @@ impl InnerMultipart {
match field.borrow_mut().poll(safety) {
Poll::Pending => return Poll::Pending,
Poll::Ready(Some(Ok(_))) => continue,
Poll::Ready(Some(Err(err))) => {
return Poll::Ready(Some(Err(err)))
}
Poll::Ready(Some(Err(err))) => return Poll::Ready(Some(Err(err))),
Poll::Ready(None) => true,
}
}
@ -289,8 +286,7 @@ impl InnerMultipart {
match self.state {
// read until first boundary
InnerState::FirstBoundary => {
match InnerMultipart::skip_until_boundary(&mut payload, &self.boundary)?
{
match InnerMultipart::skip_until_boundary(&mut payload, &self.boundary)? {
Some(eof) => {
if eof {
self.state = InnerState::Eof;
@ -667,9 +663,7 @@ impl InnerField {
Ok(None) => Poll::Pending,
Ok(Some(line)) => {
if line.as_ref() != b"\r\n" {
log::warn!(
"multipart field did not read all the data or it is malformed"
);
log::warn!("multipart field did not read all the data or it is malformed");
}
Poll::Ready(None)
}