mirror of
https://github.com/actix/actix-website
synced 2025-02-02 12:19:04 +01:00
27 lines
646 B
Rust
27 lines
646 B
Rust
// <streaming>
|
|
use actix_web::{get, web, Error, HttpResponse};
|
|
use futures::StreamExt;
|
|
|
|
#[get("/")]
|
|
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);
|
|
}
|
|
|
|
Ok(HttpResponse::Ok().finish())
|
|
}
|
|
// </streaming>
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
use actix_web::{App, HttpServer};
|
|
|
|
HttpServer::new(|| App::new().service(index))
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|