1
0
mirror of https://github.com/actix/actix-website synced 2024-11-25 01:02:58 +01:00
actix-website/examples/url-dispatch/src/pred.rs

20 lines
470 B
Rust
Raw Normal View History

2018-05-24 19:13:55 +02:00
// <pred>
2018-07-21 14:21:41 +02:00
use actix_web::{http, server::Request, pred::Predicate, App, HttpResponse};
2018-05-24 19:13:55 +02:00
struct ContentTypeHeader;
impl<S: 'static> Predicate<S> for ContentTypeHeader {
2018-07-21 14:21:41 +02:00
fn check(&self, req: &Request, state: &S) -> bool {
2018-05-24 19:13:55 +02:00
req.headers().contains_key(http::header::CONTENT_TYPE)
}
}
fn main() {
App::new().resource("/index.html", |r| {
r.route()
.filter(ContentTypeHeader)
.f(|_| HttpResponse::Ok())
});
}
// </pred>