Hi, I'm trying to build some http server using hyper.
I'm trying to get body of http request as Vec<u8>
, but so far I haven't been able to get it to work.
I've checked out example server implementation, but this basically just passes request body to response body.
So far I've tried below, but this gets blocked at "before fold"
.
fn call(&self, req: Request) -> Self::Future {
let (method, uri, _version, headers, body) = req.deconstruct();
match (&method, uri.path()) {
(&Post, "/echo") => {
let res = Response::new();
let input: Vec<u8> = if let Some(len) = headers.get::<ContentLength>() {
Vec::with_capacity(**len as usize)
} else {
Vec::new()
};
debug!("before fold");
future::result(body.fold(input, |mut acc, chunk| {
acc.extend_from_slice(chunk.as_ref());
Ok::<_, hyper::Error>(acc)
}).and_then(move |body_vec| {
debug!("body_vec ready: {}", body_vec.len());
future::ok(res.with_body(body_vec))
}).wait())
},
_ => future::ok(Response::new().with_status(StatusCode::NotFound)),
}
}
I'm still new to Futures
and I'm trying to adapt to hyper's shift to Tokio based API.
It would be great if someone can point me to the right direction.
Thanks!