index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2021-04-27 20:17:29.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2021-04-27 20:17:29.0 +00:00:00
commit
c47b898f004382f81e30a9bb8bd83c072cb15ae1 [patch]
tree
aa0b1c4bc9e8f3c0a5af96a6e4399adc905beee9
parent
1636b21e7dae2055e767ba52ba933d41022aae9d
download
c47b898f004382f81e30a9bb8bd83c072cb15ae1.tar.gz

refactor: remove few custom filters



Diff

 src/filters.rs   | 20 --------------------
 src/lib.rs       |  1 -
 src/rejection.rs | 14 --------------
 3 files changed, 35 deletions(-)

diff --git a/src/filters.rs b/src/filters.rs
deleted file mode 100644
index bcc8b40..0000000
--- a/src/filters.rs
+++ /dev/null
@@ -1,20 +0,0 @@
use warp::{reject, Filter, Rejection};

use crate::rejection::InvalidHeader;

/// Warp filter in order to check for an `Accept-Encoding` header value.
pub fn has_accept_encoding(
    occurrence: &'static str,
) -> impl Filter<Extract = (), Error = Rejection> + Copy {
    warp::header::<String>("accept-encoding")
        .and_then(move |s: String| async move {
            if s.contains(occurrence) {
                Ok(())
            } else {
                Err(reject::custom(InvalidHeader {
                    name: "accept-encoding",
                }))
            }
        })
        .untuple_one()
}
diff --git a/src/lib.rs b/src/lib.rs
index 91a5d4c..57c9027 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,7 +7,6 @@ pub mod cache;
pub mod compression;
pub mod config;
pub mod cors;
pub mod filters;
pub mod helpers;
pub mod logger;
pub mod rejection;
diff --git a/src/rejection.rs b/src/rejection.rs
index 8f99beb..75a825a 100644
--- a/src/rejection.rs
+++ b/src/rejection.rs
@@ -44,17 +44,3 @@ pub async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> 

    Ok(warp::reply::with_status(warp::reply::html(content), code))
}

/// Custom invalid request header rejection.
#[derive(Debug)]
pub struct InvalidHeader {
    pub name: &'static str,
}

impl ::std::fmt::Display for InvalidHeader {
    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        write!(f, "Invalid request header {:?}", self.name)
    }
}

impl warp::reject::Reject for InvalidHeader {}