xref: /DragonOS/user/apps/test-backlog/src/main.rs (revision fae6e9ade46a52976ad5d099643d51cc20876448)
1 use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
2 use std::io;
3 
4 async fn index(req: HttpRequest) -> HttpResponse {
5     // 获取请求方法
6     let method = req.method().to_string();
7     // 获取请求路径
8     let path = req.path().to_string();
9     // 获取请求头部信息
10     let headers = req.headers().clone();
11     // 获取查询参数
12     let query_params = req.query_string().to_string();
13 
14     // 打印请求信息
15     println!("Received {} request to {}", method, path);
16     println!("Headers: {:?}", headers);
17     println!("Query params: {}", query_params);
18 
19     // 返回响应
20     HttpResponse::Ok().body("Hello, World!")
21 }
22 
23 #[actix_web::main]
24 async fn main() -> io::Result<()> {
25     // 设置 TCP backlog 大小为 5
26     let backlog_size = 5;
27 
28     HttpServer::new(|| App::new().route("/", web::get().to(index)))
29         .backlog(backlog_size) // 设置 TCP backlog 大小
30         .bind("0.0.0.0:12580")?
31         .run()
32         .await
33 }
34