1
0
mirror of https://github.com/actix/actix-website synced 2025-02-08 22:36:07 +01:00

27 lines
646 B
Rust
Raw Normal View History

2019-06-17 14:34:23 -04:00
// <streaming>
2020-09-12 16:21:54 +01:00
use actix_web::{get, web, Error, HttpResponse};
use futures::StreamExt;
2019-06-17 14:34:23 -04:00
2020-09-12 16:21:54 +01:00
#[get("/")]
2019-12-29 02:32:47 +09:00
async fn index(mut body: web::Payload) -> Result<HttpResponse, Error> {
let mut bytes = web::BytesMut::new();
while let Some(item) = body.next().await {
let item = item?;
println!("Chunk: {:?}", &item);
bytes.extend_from_slice(&item);
2019-12-29 02:32:47 +09:00
}
Ok(HttpResponse::Ok().finish())
2019-06-26 01:27:17 -04:00
}
2019-06-17 14:34:23 -04:00
// </streaming>
2019-06-26 01:27:17 -04:00
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 02:32:47 +09:00
async fn main() -> std::io::Result<()> {
2019-06-26 01:27:17 -04:00
use actix_web::{App, HttpServer};
2020-09-12 16:21:54 +01:00
HttpServer::new(|| App::new().service(index))
2022-02-26 03:56:24 +00:00
.bind(("127.0.0.1", 8080))?
2019-06-26 01:27:17 -04:00
.run()
2019-12-29 02:32:47 +09:00
.await
2019-06-26 01:27:17 -04:00
}