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

Check format and tweak CI config (#1619)

This commit is contained in:
Yuki Okushi
2020-07-22 08:28:33 +09:00
committed by GitHub
parent 701bdacfa2
commit 92b5bcd13f
45 changed files with 276 additions and 272 deletions

View File

@ -26,7 +26,6 @@ use actix_web::{web, FromRequest, HttpRequest, HttpResponse};
use bytes::Bytes;
use futures_core::Stream;
use futures_util::future::{ok, ready, Either, FutureExt, LocalBoxFuture, Ready};
use mime;
use mime_guess::from_ext;
use percent_encoding::{utf8_percent_encode, CONTROLS};
use v_htmlescape::escape as escape_html_entity;
@ -250,6 +249,8 @@ pub struct Files {
renderer: Rc<DirectoryRenderer>,
mime_override: Option<Rc<MimeOverride>>,
file_flags: named::Flags,
// FIXME: Should re-visit later.
#[allow(clippy::redundant_allocation)]
guards: Option<Rc<Box<dyn Guard>>>,
}
@ -462,6 +463,8 @@ pub struct FilesService {
renderer: Rc<DirectoryRenderer>,
mime_override: Option<Rc<MimeOverride>>,
file_flags: named::Flags,
// FIXME: Should re-visit later.
#[allow(clippy::redundant_allocation)]
guards: Option<Rc<Box<dyn Guard>>>,
}
@ -501,11 +504,8 @@ impl Service for FilesService {
// execute user defined guards
(**guard).check(req.head())
} else {
// default behaviour
match *req.method() {
Method::HEAD | Method::GET => true,
_ => false,
}
// default behavior
matches!(*req.method(), Method::HEAD | Method::GET)
};
if !is_method_valid {
@ -952,9 +952,7 @@ mod tests {
#[actix_rt::test]
async fn test_named_file_content_range_headers() {
let srv = test::start(|| {
App::new().service(Files::new("/", "."))
});
let srv = test::start(|| App::new().service(Files::new("/", ".")));
// Valid range header
let response = srv
@ -979,9 +977,7 @@ mod tests {
#[actix_rt::test]
async fn test_named_file_content_length_headers() {
let srv = test::start(|| {
App::new().service(Files::new("/", "."))
});
let srv = test::start(|| App::new().service(Files::new("/", ".")));
// Valid range header
let response = srv
@ -1020,15 +1016,9 @@ mod tests {
#[actix_rt::test]
async fn test_head_content_length_headers() {
let srv = test::start(|| {
App::new().service(Files::new("/", "."))
});
let srv = test::start(|| App::new().service(Files::new("/", ".")));
let response = srv
.head("/tests/test.binary")
.send()
.await
.unwrap();
let response = srv.head("/tests/test.binary").send().await.unwrap();
let content_length = response
.headers()
@ -1097,12 +1087,10 @@ mod tests {
#[actix_rt::test]
async fn test_named_file_content_encoding() {
let mut srv = test::init_service(App::new().wrap(Compress::default()).service(
web::resource("/").to(|| {
async {
NamedFile::open("Cargo.toml")
.unwrap()
.set_content_encoding(header::ContentEncoding::Identity)
}
web::resource("/").to(|| async {
NamedFile::open("Cargo.toml")
.unwrap()
.set_content_encoding(header::ContentEncoding::Identity)
}),
))
.await;
@ -1119,12 +1107,10 @@ mod tests {
#[actix_rt::test]
async fn test_named_file_content_encoding_gzip() {
let mut srv = test::init_service(App::new().wrap(Compress::default()).service(
web::resource("/").to(|| {
async {
NamedFile::open("Cargo.toml")
.unwrap()
.set_content_encoding(header::ContentEncoding::Gzip)
}
web::resource("/").to(|| async {
NamedFile::open("Cargo.toml")
.unwrap()
.set_content_encoding(header::ContentEncoding::Gzip)
}),
))
.await;

View File

@ -8,7 +8,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::os::unix::fs::MetadataExt;
use bitflags::bitflags;
use mime;
use mime_guess::from_path;
use actix_http::body::SizedStream;
@ -90,7 +89,7 @@ impl NamedFile {
};
let ct = from_path(&path).first_or_octet_stream();
let disposition_type = match ct.type_() {
let disposition = match ct.type_() {
mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
_ => DispositionType::Attachment,
};
@ -104,8 +103,8 @@ impl NamedFile {
}))
}
let cd = ContentDisposition {
disposition: disposition_type,
parameters: parameters,
disposition,
parameters,
};
(ct, cd)
};