我正在尝试使用 hyper 0.11.2 读取 POSTed JSON。打印“Reached”后,我看不到任何事情发生。
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)
}
输出:
Reached ...
Reached xxx Body(Body { [stream of values] })