I used the following code to read and parse JSON body of the Request, however wait() blocks the running thread forever:
use hyper::server::{Request, Response};
use hyper::header::{ContentLength, ContentType};
use hyper::{Body, StatusCode, self};
use futures::stream::Stream;
use futures::Future;
use serde_json::{self, Value};
pub fn parse(req: Request) -> Response {
let req_body = match req.body().concat2().wait() {
Ok(body) => {
if let Ok(value) = serde_json::from_slice(&body) {
value
} else {
return Response::new().with_status(StatusCode::InternalServerError);
}
},
_ => return Response::new().with_status(StatusCode::InternalServerError),
};
// unreachable
...
}