mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 17:07:01 +02:00
remove Deref
This commit is contained in:
63
src/guard.rs
63
src/guard.rs
@@ -73,6 +73,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Guard for F
|
||||
where
|
||||
F: Fn(&RequestHead) -> bool,
|
||||
{
|
||||
fn check(&self, head: &RequestHead) -> bool {
|
||||
(self)(head)
|
||||
}
|
||||
}
|
||||
|
||||
/// Return guard that matches if any of supplied guards.
|
||||
///
|
||||
/// ```rust
|
||||
@@ -300,13 +309,13 @@ mod tests {
|
||||
.to_http_request();
|
||||
|
||||
let pred = Header("transfer-encoding", "chunked");
|
||||
assert!(pred.check(&req));
|
||||
assert!(pred.check(req.head()));
|
||||
|
||||
let pred = Header("transfer-encoding", "other");
|
||||
assert!(!pred.check(&req));
|
||||
assert!(!pred.check(req.head()));
|
||||
|
||||
let pred = Header("content-type", "other");
|
||||
assert!(!pred.check(&req));
|
||||
assert!(!pred.check(req.head()));
|
||||
}
|
||||
|
||||
// #[test]
|
||||
@@ -332,50 +341,50 @@ mod tests {
|
||||
.method(Method::POST)
|
||||
.to_http_request();
|
||||
|
||||
assert!(Get().check(&req));
|
||||
assert!(!Get().check(&req2));
|
||||
assert!(Post().check(&req2));
|
||||
assert!(!Post().check(&req));
|
||||
assert!(Get().check(req.head()));
|
||||
assert!(!Get().check(req2.head()));
|
||||
assert!(Post().check(req2.head()));
|
||||
assert!(!Post().check(req.head()));
|
||||
|
||||
let r = TestRequest::default().method(Method::PUT).to_http_request();
|
||||
assert!(Put().check(&r));
|
||||
assert!(!Put().check(&req));
|
||||
assert!(Put().check(r.head()));
|
||||
assert!(!Put().check(req.head()));
|
||||
|
||||
let r = TestRequest::default()
|
||||
.method(Method::DELETE)
|
||||
.to_http_request();
|
||||
assert!(Delete().check(&r));
|
||||
assert!(!Delete().check(&req));
|
||||
assert!(Delete().check(r.head()));
|
||||
assert!(!Delete().check(req.head()));
|
||||
|
||||
let r = TestRequest::default()
|
||||
.method(Method::HEAD)
|
||||
.to_http_request();
|
||||
assert!(Head().check(&r));
|
||||
assert!(!Head().check(&req));
|
||||
assert!(Head().check(r.head()));
|
||||
assert!(!Head().check(req.head()));
|
||||
|
||||
let r = TestRequest::default()
|
||||
.method(Method::OPTIONS)
|
||||
.to_http_request();
|
||||
assert!(Options().check(&r));
|
||||
assert!(!Options().check(&req));
|
||||
assert!(Options().check(r.head()));
|
||||
assert!(!Options().check(req.head()));
|
||||
|
||||
let r = TestRequest::default()
|
||||
.method(Method::CONNECT)
|
||||
.to_http_request();
|
||||
assert!(Connect().check(&r));
|
||||
assert!(!Connect().check(&req));
|
||||
assert!(Connect().check(r.head()));
|
||||
assert!(!Connect().check(req.head()));
|
||||
|
||||
let r = TestRequest::default()
|
||||
.method(Method::PATCH)
|
||||
.to_http_request();
|
||||
assert!(Patch().check(&r));
|
||||
assert!(!Patch().check(&req));
|
||||
assert!(Patch().check(r.head()));
|
||||
assert!(!Patch().check(req.head()));
|
||||
|
||||
let r = TestRequest::default()
|
||||
.method(Method::TRACE)
|
||||
.to_http_request();
|
||||
assert!(Trace().check(&r));
|
||||
assert!(!Trace().check(&req));
|
||||
assert!(Trace().check(r.head()));
|
||||
assert!(!Trace().check(req.head()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -384,13 +393,13 @@ mod tests {
|
||||
.method(Method::TRACE)
|
||||
.to_http_request();
|
||||
|
||||
assert!(Not(Get()).check(&r));
|
||||
assert!(!Not(Trace()).check(&r));
|
||||
assert!(Not(Get()).check(r.head()));
|
||||
assert!(!Not(Trace()).check(r.head()));
|
||||
|
||||
assert!(All(Trace()).and(Trace()).check(&r));
|
||||
assert!(!All(Get()).and(Trace()).check(&r));
|
||||
assert!(All(Trace()).and(Trace()).check(r.head()));
|
||||
assert!(!All(Get()).and(Trace()).check(r.head()));
|
||||
|
||||
assert!(Any(Get()).or(Trace()).check(&r));
|
||||
assert!(!Any(Get()).or(Get()).check(&r));
|
||||
assert!(Any(Get()).or(Trace()).check(r.head()));
|
||||
assert!(!Any(Get()).or(Get()).check(r.head()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user