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

20 lines
479 B
Rust
Raw Normal View History

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