refactor: remove few custom filters
Diff
src/filters.rs | 20 --------------------
src/lib.rs | 1 -
src/rejection.rs | 14 --------------
3 files changed, 35 deletions(-)
@@ -1,20 +0,0 @@
use warp::{reject, Filter, Rejection};
use crate::rejection::InvalidHeader;
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()
}
@@ -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;
@@ -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))
}
#[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 {}