I am trying to read POSTed JSON using hyper 0.11.2. I don't see anything happening after "Reached" is printed.
fn call(&self, req: hyper::server::Request) -> Self::Future {
let mut response: Response = Response::new();
match (req.method(), req.path()) {
(&Method::Post, "/assests") => {
println!("Reached ... "); //POST: 200 OK
//let (method, uri, _version, head
let mut res: Response = Response::new();
if let Some(len) = req.headers().get::<ContentLength>() {
res.headers_mut().set(len.clone());
}
println!("Reached xxx {:?}", req.body());
res.with_body("req.body()");
}
_ => {
response.set_status(StatusCode::NotFound);
}
};
futures::future::ok(response)
}
Output:
Reached ...
Reached xxx Body(Body { [stream of values] })
You created a new
Responsecalledresponse, then created a secondResponsecalledres. You then modifyresand then throw it away, returningresponsefrom your function. If you return the thing you modify, your server returns the string"req.body()", just as you have specified.I would not set the content-length to an invalid value — your returned string does not match the length of the uploaded data.