2019-06-25 18:20:36 -04:00
|
|
|
// <guard>
|
2022-02-26 03:56:24 +00:00
|
|
|
use actix_web::{
|
|
|
|
guard::{Guard, GuardContext},
|
|
|
|
http, HttpResponse,
|
|
|
|
};
|
2019-06-25 18:20:36 -04:00
|
|
|
|
|
|
|
struct ContentTypeHeader;
|
|
|
|
|
|
|
|
impl Guard for ContentTypeHeader {
|
2022-02-26 03:56:24 +00:00
|
|
|
fn check(&self, req: &GuardContext) -> bool {
|
|
|
|
req.head()
|
|
|
|
.headers()
|
|
|
|
.contains_key(http::header::CONTENT_TYPE)
|
2019-06-25 18:20:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-29 04:10:02 +09:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{web, App, HttpServer};
|
|
|
|
|
2019-06-25 18:20:36 -04:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new().route(
|
|
|
|
"/",
|
2022-02-26 03:56:24 +00:00
|
|
|
web::route().guard(ContentTypeHeader).to(HttpResponse::Ok),
|
2019-06-25 18:20:36 -04:00
|
|
|
)
|
|
|
|
})
|
2022-02-26 03:56:24 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-25 18:20:36 -04:00
|
|
|
.run()
|
2019-12-29 04:10:02 +09:00
|
|
|
.await
|
2019-06-25 18:20:36 -04:00
|
|
|
}
|
|
|
|
// </guard>
|