1
0
mirror of https://github.com/actix/actix-website synced 2025-02-23 20:53:01 +01:00
2022-02-26 03:56:24 +00:00

32 lines
636 B
Rust

// <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>