1
0
mirror of https://github.com/actix/actix-website synced 2025-02-02 12:19:04 +01:00

31 lines
772 B
Rust
Raw Normal View History

2019-06-17 15:15:33 -04:00
// <identity-two>
use actix_web::{
2022-02-26 03:56:24 +00:00
get, http::header::ContentEncoding, middleware, App, HttpResponse, HttpServer,
2019-06-17 15:15:33 -04:00
};
static HELLO_WORLD: &[u8] = &[
2022-02-26 03:56:24 +00:00
0x1f, 0x8b, 0x08, 0x00, 0xa2, 0x30, 0x10, 0x5c, 0x00, 0x03, 0xcb, 0x48, 0xcd, 0xc9, 0xc9,
0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00,
0x00, 0x00,
2019-06-17 15:15:33 -04:00
];
2020-09-12 16:21:54 +01:00
#[get("/")]
2019-12-29 02:59:48 +09:00
async fn index() -> HttpResponse {
2019-06-17 15:15:33 -04:00
HttpResponse::Ok()
2022-02-26 03:56:24 +00:00
.insert_header(ContentEncoding::Gzip)
2019-06-17 15:15:33 -04:00
.body(HELLO_WORLD)
}
// </identity-two>
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 02:59:48 +09:00
async fn main() -> std::io::Result<()> {
2019-06-26 14:15:03 -04:00
HttpServer::new(|| {
App::new()
.wrap(middleware::Compress::default())
2020-09-12 16:21:54 +01:00
.service(index)
2019-06-26 14:15:03 -04:00
})
2022-02-26 03:56:24 +00:00
.bind(("127.0.0.1", 8080))?
2019-06-26 14:15:03 -04:00
.run()
2019-12-29 02:59:48 +09:00
.await
}