mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into custom_methods
This commit is contained in:
commit
7115c29a55
|
@ -142,7 +142,7 @@ impl Files {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set custom directory renderer
|
||||
/// Set custom directory renderer.
|
||||
pub fn files_listing_renderer<F>(mut self, f: F) -> Self
|
||||
where
|
||||
for<'r, 's> F:
|
||||
|
@ -152,7 +152,7 @@ impl Files {
|
|||
self
|
||||
}
|
||||
|
||||
/// Specifies mime override callback
|
||||
/// Specifies MIME override callback.
|
||||
pub fn mime_override<F>(mut self, f: F) -> Self
|
||||
where
|
||||
F: Fn(&mime::Name<'_>) -> DispositionType + 'static,
|
||||
|
@ -390,3 +390,42 @@ impl ServiceFactory<ServiceRequest> for Files {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::{
|
||||
http::StatusCode,
|
||||
test::{self, TestRequest},
|
||||
App, HttpResponse,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[actix_web::test]
|
||||
async fn custom_files_listing_renderer() {
|
||||
let srv = test::init_service(
|
||||
App::new().service(
|
||||
Files::new("/", "./tests")
|
||||
.show_files_listing()
|
||||
.files_listing_renderer(|dir, req| {
|
||||
Ok(ServiceResponse::new(
|
||||
req.clone(),
|
||||
HttpResponse::Ok().body(dir.path.to_str().unwrap().to_owned()),
|
||||
))
|
||||
}),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = TestRequest::with_uri("/").to_request();
|
||||
let res = test::call_service(&srv, req).await;
|
||||
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
let body = test::read_body(res).await;
|
||||
assert!(
|
||||
body.ends_with(b"actix-files/tests/"),
|
||||
"body {:?} does not end with `actix-files/tests/`",
|
||||
body
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ serde_json = "1.0"
|
|||
slab = "0.4"
|
||||
serde_urlencoded = "0.7"
|
||||
tls-openssl = { version = "0.10.9", package = "openssl", optional = true }
|
||||
tokio = { version = "1.18.4", features = ["sync"] }
|
||||
tokio = { version = "1.18.5", features = ["sync"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-web = { version = "4", default-features = false, features = ["cookies"] }
|
||||
|
|
|
@ -77,7 +77,7 @@ mime = "0.3"
|
|||
percent-encoding = "2.1"
|
||||
pin-project-lite = "0.2"
|
||||
smallvec = "1.6.1"
|
||||
tokio = { version = "1.18.4", features = [] }
|
||||
tokio = { version = "1.18.5", features = [] }
|
||||
tokio-util = { version = "0.7", features = ["io", "codec"] }
|
||||
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||
|
||||
|
@ -119,7 +119,7 @@ serde_json = "1.0"
|
|||
static_assertions = "1"
|
||||
tls-openssl = { package = "openssl", version = "0.10.9" }
|
||||
tls-rustls = { package = "rustls", version = "0.20.0" }
|
||||
tokio = { version = "1.18.4", features = ["net", "rt", "macros"] }
|
||||
tokio = { version = "1.18.5", features = ["net", "rt", "macros"] }
|
||||
|
||||
[[example]]
|
||||
name = "ws"
|
||||
|
|
|
@ -30,5 +30,5 @@ memchr = "2.5"
|
|||
actix-rt = "2.2"
|
||||
actix-http = "3"
|
||||
futures-util = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
tokio = { version = "1.18.4", features = ["sync"] }
|
||||
tokio = { version = "1.18.5", features = ["sync"] }
|
||||
tokio-stream = "0.1"
|
||||
|
|
|
@ -45,4 +45,4 @@ serde_json = "1"
|
|||
serde_urlencoded = "0.7"
|
||||
tls-openssl = { package = "openssl", version = "0.10.9", optional = true }
|
||||
tls-rustls = { package = "rustls", version = "0.20.0", optional = true }
|
||||
tokio = { version = "1.18.4", features = ["sync"] }
|
||||
tokio = { version = "1.18.5", features = ["sync"] }
|
||||
|
|
|
@ -23,7 +23,7 @@ bytes = "1"
|
|||
bytestring = "1"
|
||||
futures-core = { version = "0.3.17", default-features = false }
|
||||
pin-project-lite = "0.2"
|
||||
tokio = { version = "1.18.4", features = ["sync"] }
|
||||
tokio = { version = "1.18.5", features = ["sync"] }
|
||||
tokio-util = { version = "0.7", features = ["codec"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -115,7 +115,7 @@ serde = { version = "1.0", features = ["derive"] }
|
|||
static_assertions = "1"
|
||||
tls-openssl = { package = "openssl", version = "0.10.9" }
|
||||
tls-rustls = { package = "rustls", version = "0.20.0" }
|
||||
tokio = { version = "1.18.4", features = ["rt-multi-thread", "macros"] }
|
||||
tokio = { version = "1.18.5", features = ["rt-multi-thread", "macros"] }
|
||||
zstd = "0.12"
|
||||
|
||||
[[test]]
|
||||
|
|
|
@ -80,7 +80,7 @@ rand = "0.8"
|
|||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_urlencoded = "0.7"
|
||||
tokio = { version = "1.18.4", features = ["sync"] }
|
||||
tokio = { version = "1.18.5", features = ["sync"] }
|
||||
|
||||
cookie = { version = "0.16", features = ["percent-encode"], optional = true }
|
||||
|
||||
|
@ -106,7 +106,7 @@ futures-util = { version = "0.3.17", default-features = false }
|
|||
static_assertions = "1.1"
|
||||
rcgen = "0.9"
|
||||
rustls-pemfile = "1"
|
||||
tokio = { version = "1.18.4", features = ["rt-multi-thread", "macros"] }
|
||||
tokio = { version = "1.18.5", features = ["rt-multi-thread", "macros"] }
|
||||
zstd = "0.12"
|
||||
|
||||
[[example]]
|
||||
|
|
Loading…
Reference in New Issue