2019-06-17 14:34:23 -04:00
|
|
|
// <streaming>
|
2020-09-12 16:21:54 +01:00
|
|
|
use actix_web::{get, web, Error, HttpResponse};
|
2020-01-23 10:17:13 +09:00
|
|
|
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 {
|
2020-03-01 15:18:22 -05:00
|
|
|
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))
|
|
|
|
.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
|
|
|
}
|