Skip to content

Commit

Permalink
apply standard formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Jul 17, 2023
1 parent 60c76c5 commit 79a38e0
Show file tree
Hide file tree
Showing 138 changed files with 911 additions and 1,175 deletions.
5 changes: 3 additions & 2 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
max_width = 96
reorder_imports = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
use_field_init_shorthand = true
5 changes: 2 additions & 3 deletions actix-files/src/chunked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use std::{
};

use actix_web::{error::Error, web::Bytes};
use futures_core::{ready, Stream};
use pin_project_lite::pin_project;

#[cfg(feature = "experimental-io-uring")]
use bytes::BytesMut;
use futures_core::{ready, Stream};
use pin_project_lite::pin_project;

use super::named::File;

Expand Down
7 changes: 6 additions & 1 deletion actix-files/src/directory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{fmt::Write, fs::DirEntry, io, path::Path, path::PathBuf};
use std::{
fmt::Write,
fs::DirEntry,
io,
path::{Path, PathBuf},
};

use actix_web::{dev::ServiceResponse, HttpRequest, HttpResponse};
use percent_encoding::{utf8_percent_encode, CONTROLS};
Expand Down
11 changes: 3 additions & 8 deletions actix-files/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use std::{
use actix_service::{boxed, IntoServiceFactory, ServiceFactory, ServiceFactoryExt};
use actix_web::{
dev::{
AppService, HttpServiceFactory, RequestHead, ResourceDef, ServiceRequest,
ServiceResponse,
AppService, HttpServiceFactory, RequestHead, ResourceDef, ServiceRequest, ServiceResponse,
},
error::Error,
guard::Guard,
Expand Down Expand Up @@ -301,12 +300,8 @@ impl Files {
pub fn default_handler<F, U>(mut self, f: F) -> Self
where
F: IntoServiceFactory<U, ServiceRequest>,
U: ServiceFactory<
ServiceRequest,
Config = (),
Response = ServiceResponse,
Error = Error,
> + 'static,
U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error>
+ 'static,
{
// create and configure default resource
self.default = Rc::new(RefCell::new(Some(Rc::new(boxed::factory(
Expand Down
35 changes: 16 additions & 19 deletions actix-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

use std::path::Path;

use actix_service::boxed::{BoxService, BoxServiceFactory};
use actix_web::{
dev::{RequestHead, ServiceRequest, ServiceResponse},
error::Error,
http::header::DispositionType,
};
use mime_guess::from_ext;
use std::path::Path;

mod chunked;
mod directory;
Expand All @@ -37,16 +38,15 @@ mod path_buf;
mod range;
mod service;

pub use self::chunked::ChunkedReadFile;
pub use self::directory::Directory;
pub use self::files::Files;
pub use self::named::NamedFile;
pub use self::range::HttpRange;
pub use self::service::FilesService;

use self::directory::{directory_listing, DirectoryRenderer};
use self::error::FilesError;
use self::path_buf::PathBufWrap;
pub use self::{
chunked::ChunkedReadFile, directory::Directory, files::Files, named::NamedFile,
range::HttpRange, service::FilesService,
};
use self::{
directory::{directory_listing, DirectoryRenderer},
error::FilesError,
path_buf::PathBufWrap,
};

type HttpService = BoxService<ServiceRequest, ServiceResponse, Error>;
type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
Expand Down Expand Up @@ -554,10 +554,9 @@ mod tests {

#[actix_rt::test]
async fn test_static_files_with_spaces() {
let srv = test::init_service(
App::new().service(Files::new("/", ".").index_file("Cargo.toml")),
)
.await;
let srv =
test::init_service(App::new().service(Files::new("/", ".").index_file("Cargo.toml")))
.await;
let request = TestRequest::get()
.uri("/tests/test%20space.binary")
.to_request();
Expand Down Expand Up @@ -667,8 +666,7 @@ mod tests {
#[actix_rt::test]
async fn test_static_files() {
let srv =
test::init_service(App::new().service(Files::new("/", ".").show_files_listing()))
.await;
test::init_service(App::new().service(Files::new("/", ".").show_files_listing())).await;
let req = TestRequest::with_uri("/missing").to_request();

let resp = test::call_service(&srv, req).await;
Expand All @@ -681,8 +679,7 @@ mod tests {
assert_eq!(resp.status(), StatusCode::NOT_FOUND);

let srv =
test::init_service(App::new().service(Files::new("/", ".").show_files_listing()))
.await;
test::init_service(App::new().service(Files::new("/", ".").show_files_listing())).await;
let req = TestRequest::with_uri("/tests").to_request();
let resp = test::call_service(&srv, req).await;
assert_eq!(
Expand Down
12 changes: 6 additions & 6 deletions actix-files/src/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use std::{
use actix_web::{
body::{self, BoxBody, SizedStream},
dev::{
self, AppService, HttpServiceFactory, ResourceDef, Service, ServiceFactory,
ServiceRequest, ServiceResponse,
self, AppService, HttpServiceFactory, ResourceDef, Service, ServiceFactory, ServiceRequest,
ServiceResponse,
},
http::{
header::{
self, Charset, ContentDisposition, ContentEncoding, DispositionParam,
DispositionType, ExtendedValue, HeaderValue,
self, Charset, ContentDisposition, ContentEncoding, DispositionParam, DispositionType,
ExtendedValue, HeaderValue,
},
StatusCode,
},
Expand Down Expand Up @@ -85,6 +85,7 @@ pub struct NamedFile {

#[cfg(not(feature = "experimental-io-uring"))]
pub(crate) use std::fs::File;

#[cfg(feature = "experimental-io-uring")]
pub(crate) use tokio_uring::fs::File;

Expand Down Expand Up @@ -139,8 +140,7 @@ impl NamedFile {
_ => DispositionType::Attachment,
};

let mut parameters =
vec![DispositionParam::Filename(String::from(filename.as_ref()))];
let mut parameters = vec![DispositionParam::Filename(String::from(filename.as_ref()))];

if !filename.is_ascii() {
parameters.push(DispositionParam::FilenameExt(ExtendedValue {
Expand Down
4 changes: 2 additions & 2 deletions actix-files/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl HttpRange {
/// `header` is HTTP Range header (e.g. `bytes=bytes=0-9`).
/// `size` is full size of response (file).
pub fn parse(header: &str, size: u64) -> Result<Vec<HttpRange>, ParseRangeErr> {
let ranges = http_range::HttpRange::parse(header, size)
.map_err(|err| ParseRangeErr(err.into()))?;
let ranges =
http_range::HttpRange::parse(header, size).map_err(|err| ParseRangeErr(err.into()))?;

Ok(ranges
.iter()
Expand Down
21 changes: 7 additions & 14 deletions actix-files/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ impl FilesService {
}
}

fn serve_named_file(
&self,
req: ServiceRequest,
mut named_file: NamedFile,
) -> ServiceResponse {
fn serve_named_file(&self, req: ServiceRequest, mut named_file: NamedFile) -> ServiceResponse {
if let Some(ref mime_override) = self.mime_override {
let new_disposition = mime_override(&named_file.content_type.type_());
named_file.content_disposition.disposition = new_disposition;
Expand Down Expand Up @@ -120,13 +116,11 @@ impl Service<ServiceRequest> for FilesService {
));
}

let path_on_disk = match PathBufWrap::parse_path(
req.match_info().unprocessed(),
this.hidden_files,
) {
Ok(item) => item,
Err(err) => return Ok(req.error_response(err)),
};
let path_on_disk =
match PathBufWrap::parse_path(req.match_info().unprocessed(), this.hidden_files) {
Ok(item) => item,
Err(err) => return Ok(req.error_response(err)),
};

if let Some(filter) = &this.path_filter {
if !filter(path_on_disk.as_ref(), req.head()) {
Expand Down Expand Up @@ -177,8 +171,7 @@ impl Service<ServiceRequest> for FilesService {
match NamedFile::open_async(&path).await {
Ok(mut named_file) => {
if let Some(ref mime_override) = this.mime_override {
let new_disposition =
mime_override(&named_file.content_type.type_());
let new_disposition = mime_override(&named_file.content_type.type_());
named_file.content_disposition.disposition = new_disposition;
}
named_file.flags = this.file_flags;
Expand Down
3 changes: 1 addition & 2 deletions actix-files/tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ async fn test_utf8_file_contents() {

// disable UTF-8 attribute
let srv =
test::init_service(App::new().service(Files::new("/", "./tests").prefer_utf8(false)))
.await;
test::init_service(App::new().service(Files::new("/", "./tests").prefer_utf8(false))).await;

let req = TestRequest::with_uri("/utf8.txt").to_request();
let res = test::call_service(&srv, req).await;
Expand Down
4 changes: 1 addition & 3 deletions actix-files/tests/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ async fn test_guard_filter() {
let srv = test::init_service(
App::new()
.service(Files::new("/", "./tests/fixtures/guards/first").guard(Host("first.com")))
.service(
Files::new("/", "./tests/fixtures/guards/second").guard(Host("second.com")),
),
.service(Files::new("/", "./tests/fixtures/guards/second").guard(Host("second.com"))),
)
.await;

Expand Down
3 changes: 1 addition & 2 deletions actix-files/tests/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use actix_web::{
async fn test_directory_traversal_prevention() {
let srv = test::init_service(App::new().service(Files::new("/", "./tests"))).await;

let req =
TestRequest::with_uri("/../../../../../../../../../../../etc/passwd").to_request();
let req = TestRequest::with_uri("/../../../../../../../../../../../etc/passwd").to_request();
let res = test::call_service(&srv, req).await;
assert_eq!(res.status(), StatusCode::NOT_FOUND);

Expand Down
5 changes: 1 addition & 4 deletions actix-http/examples/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ async fn main() -> io::Result<()> {
res.insert_header(("x-head", HeaderValue::from_static("dummy value!")));

let forty_two = req.conn_data::<u32>().unwrap().to_string();
res.insert_header((
"x-forty-two",
HeaderValue::from_str(&forty_two).unwrap(),
));
res.insert_header(("x-forty-two", HeaderValue::from_str(&forty_two).unwrap()));

Ok::<_, Infallible>(res.body("Hello world!"))
})
Expand Down
8 changes: 2 additions & 6 deletions actix-http/src/body/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ impl MessageBody for BoxBody {
cx: &mut Context<'_>,
) -> Poll<Option<Result<Bytes, Self::Error>>> {
match &mut self.0 {
BoxBodyInner::None(body) => {
Pin::new(body).poll_next(cx).map_err(|err| match err {})
}
BoxBodyInner::Bytes(body) => {
Pin::new(body).poll_next(cx).map_err(|err| match err {})
}
BoxBodyInner::None(body) => Pin::new(body).poll_next(cx).map_err(|err| match err {}),
BoxBodyInner::Bytes(body) => Pin::new(body).poll_next(cx).map_err(|err| match err {}),
BoxBodyInner::Stream(body) => Pin::new(body).poll_next(cx),
}
}
Expand Down
18 changes: 10 additions & 8 deletions actix-http/src/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ mod size;
mod sized_stream;
mod utils;

pub use self::body_stream::BodyStream;
pub use self::boxed::BoxBody;
pub use self::either::EitherBody;
pub use self::message_body::MessageBody;
pub(crate) use self::message_body::MessageBodyMapErr;
pub use self::none::None;
pub use self::size::BodySize;
pub use self::sized_stream::SizedStream;
pub use self::utils::{to_bytes, to_bytes_limited, BodyLimitExceeded};
pub use self::{
body_stream::BodyStream,
boxed::BoxBody,
either::EitherBody,
message_body::MessageBody,
none::None,
size::BodySize,
sized_stream::SizedStream,
utils::{to_bytes, to_bytes_limited, BodyLimitExceeded},
};
6 changes: 3 additions & 3 deletions actix-http/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ impl ServiceConfig {

#[cfg(test)]
mod tests {
use super::*;
use crate::{date::DATE_VALUE_LENGTH, notify_on_drop};

use actix_rt::{
task::yield_now,
time::{sleep, sleep_until},
};
use memchr::memmem;

use super::*;
use crate::{date::DATE_VALUE_LENGTH, notify_on_drop};

#[actix_rt::test]
async fn test_date_service_update() {
let settings =
Expand Down
10 changes: 4 additions & 6 deletions actix-http/src/encoding/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ use std::{

use actix_rt::task::{spawn_blocking, JoinHandle};
use bytes::Bytes;
use futures_core::{ready, Stream};

#[cfg(feature = "compress-gzip")]
use flate2::write::{GzDecoder, ZlibDecoder};

use futures_core::{ready, Stream};
#[cfg(feature = "compress-zstd")]
use zstd::stream::write::Decoder as ZstdDecoder;

Expand Down Expand Up @@ -49,9 +47,9 @@ where
))),

#[cfg(feature = "compress-gzip")]
ContentEncoding::Deflate => Some(ContentDecoder::Deflate(Box::new(
ZlibDecoder::new(Writer::new()),
))),
ContentEncoding::Deflate => Some(ContentDecoder::Deflate(Box::new(ZlibDecoder::new(
Writer::new(),
)))),

#[cfg(feature = "compress-gzip")]
ContentEncoding::Gzip => Some(ContentDecoder::Gzip(Box::new(GzDecoder::new(
Expand Down
6 changes: 2 additions & 4 deletions actix-http/src/encoding/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ use std::{
use actix_rt::task::{spawn_blocking, JoinHandle};
use bytes::Bytes;
use derive_more::Display;
use futures_core::ready;
use pin_project_lite::pin_project;

#[cfg(feature = "compress-gzip")]
use flate2::write::{GzEncoder, ZlibEncoder};

use futures_core::ready;
use pin_project_lite::pin_project;
use tracing::trace;
#[cfg(feature = "compress-zstd")]
use zstd::stream::write::Encoder as ZstdEncoder;
Expand Down
3 changes: 1 addition & 2 deletions actix-http/src/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use bytes::{Bytes, BytesMut};
mod decoder;
mod encoder;

pub use self::decoder::Decoder;
pub use self::encoder::Encoder;
pub use self::{decoder::Decoder, encoder::Encoder};

/// Special-purpose writer for streaming (de-)compression.
///
Expand Down
3 changes: 1 addition & 2 deletions actix-http/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
use std::{error::Error as StdError, fmt, io, str::Utf8Error, string::FromUtf8Error};

use derive_more::{Display, Error, From};
pub use http::Error as HttpError;
use http::{uri::InvalidUri, StatusCode};

use crate::{body::BoxBody, Response};

pub use http::Error as HttpError;

pub struct Error {
inner: Box<ErrorInner>,
}
Expand Down
4 changes: 1 addition & 3 deletions actix-http/src/h1/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use super::{
decoder::{self, PayloadDecoder, PayloadItem, PayloadType},
encoder, Message, MessageType,
};
use crate::{
body::BodySize, error::ParseError, ConnectionType, Request, Response, ServiceConfig,
};
use crate::{body::BodySize, error::ParseError, ConnectionType, Request, Response, ServiceConfig};

bitflags! {
#[derive(Debug, Clone, Copy)]
Expand Down
Loading

0 comments on commit 79a38e0

Please sign in to comment.