index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2021-01-13 14:43:26.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2021-01-13 14:43:26.0 +00:00:00
commit
f7f2bf662bbf1bfec88750f44b509b3da9ce5441 [patch]
tree
238ff68ad4904a7cc32626c42658bc347fea1db7
parent
c63b5495d3bc19d7879c6ddd1f7368cf4474cd37
download
f7f2bf662bbf1bfec88750f44b509b3da9ce5441.tar.gz

feat: some clippy warnings



Diff

 Makefile              | 5 +++++
 src/core/cache.rs     | 6 +++---
 src/core/rejection.rs | 7 +++++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 0a6ff85..bde0065 100644
--- a/Makefile
+++ b/Makefile
@@ -34,6 +34,11 @@ dev:
	@cargo make --makefile Makefile.toml watch
.PHONY: dev

lint:
	@rustc -vV
	@cargo clippy --all-features -- -D warnings
.PHONY: lint

build:
	@rustc -vV
	@cargo build --release --target $(PKG_TARGET)
diff --git a/src/core/cache.rs b/src/core/cache.rs
index 685f527..c771cb3 100644
--- a/src/core/cache.rs
+++ b/src/core/cache.rs
@@ -8,11 +8,11 @@ const CACHE_EXT_ONE_YEAR: [&str; 30] = [
/// It applies the corresponding Cache-Control headers based on a set of file types.
pub fn control_headers(res: warp::fs::File) -> warp::reply::WithHeader<warp::fs::File> {
    // Default max-age value in seconds (one day)
    let mut max_age = 60 * 60 * 24 as u64;
    let mut max_age = 60 * 60 * 24_u64;

    if let Some(ext) = res.path().extension() {
        if let Some(ext) = ext.to_str() {
            if CACHE_EXT_ONE_HOUR.iter().any(|n| *n == ext) {
            if CACHE_EXT_ONE_HOUR.iter().any(|x| *x == ext) {
                max_age = 60 * 60;
            } else if CACHE_EXT_ONE_YEAR.iter().any(|x| *x == ext) {
                max_age = 60 * 60 * 24 * 365;
@@ -34,5 +34,5 @@ pub fn control_headers(res: warp::fs::File) -> warp::reply::WithHeader<warp::fs:

/// It caps a duration value at ~136 years.
fn duration(n: u64) -> u32 {
    std::cmp::min(n.clone(), u32::MAX as u64) as u32
    std::cmp::min(n, u32::MAX as u64) as u32
}
diff --git a/src/core/rejection.rs b/src/core/rejection.rs
index d57062f..666eaef 100644
--- a/src/core/rejection.rs
+++ b/src/core/rejection.rs
@@ -7,9 +7,12 @@ use warp::{Rejection, Reply};
pub async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> {
    let code = if err.is_not_found() {
        StatusCode::NOT_FOUND
    } else if let Some(_) = err.find::<warp::filters::body::BodyDeserializeError>() {
    } else if err
        .find::<warp::filters::body::BodyDeserializeError>()
        .is_some()
    {
        StatusCode::BAD_REQUEST
    } else if let Some(_) = err.find::<warp::reject::MethodNotAllowed>() {
    } else if err.find::<warp::reject::MethodNotAllowed>().is_some() {
        StatusCode::METHOD_NOT_ALLOWED
    } else {
        StatusCode::INTERNAL_SERVER_ERROR