mirror of
https://github.com/actix/actix-website
synced 2024-11-30 11:12:57 +01:00
fd0450917d
inspired by #423
34 lines
697 B
Rust
34 lines
697 B
Rust
#![allow(dead_code)] // false positive on ContentTypeHeader
|
|
|
|
// <guard>
|
|
use actix_web::{
|
|
guard::{Guard, GuardContext},
|
|
http, HttpResponse,
|
|
};
|
|
|
|
struct ContentTypeHeader;
|
|
|
|
impl Guard for ContentTypeHeader {
|
|
fn check(&self, req: &GuardContext) -> bool {
|
|
req.head()
|
|
.headers()
|
|
.contains_key(http::header::CONTENT_TYPE)
|
|
}
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
use actix_web::{web, App, HttpServer};
|
|
|
|
HttpServer::new(|| {
|
|
App::new().route(
|
|
"/",
|
|
web::route().guard(ContentTypeHeader).to(HttpResponse::Ok),
|
|
)
|
|
})
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|
|
// </guard>
|