fixups for new hyper alpha

Body's Streawm impl was put behind the 'unstable-stream'
feature, so we won't be using it for now.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-09-28 09:54:52 +02:00
parent 29893d66ae
commit 01de528fc3
2 changed files with 10 additions and 4 deletions

View File

@ -13,7 +13,7 @@ endian_trait = { version = "0.6", features = [ "arrays" ] }
failure = "0.1"
futures-preview = "0.3.0-alpha"
http = "0.1"
hyper = { version = "0.13.0-alpha.1" }
hyper = { version = "0.13.0-alpha.2" }
lazy_static = "1.3"
proxmox = { path = "../proxmox", features = [ "api-macro" ] }
regex = "1.1"

View File

@ -179,6 +179,14 @@ async fn update_mount_point(id: String, entry: MountEntry) -> Result<String, Err
// Hyper glue
//
async fn json_body(mut body: Body) -> Result<Value, Error> {
let mut data = Vec::new();
while let Some(chunk) = body.next().await {
data.extend(chunk?);
}
Ok(serde_json::from_str(std::str::from_utf8(&data)?)?)
}
async fn route_request(request: Request<Body>) -> Result<http::Response<Body>, Error> {
let (parts, body) = request.into_parts();
let path = parts.uri.path();
@ -198,9 +206,7 @@ async fn route_request(request: Request<Body>) -> Result<http::Response<Body>, E
if let Some(ty) = parts.headers.get(http::header::CONTENT_TYPE) {
if ty.to_str()? == "application/json" {
use futures::stream::TryStreamExt;
let json =
serde_json::from_str(std::str::from_utf8(body.try_concat().await?.as_ref())?)?;
let json = json_body(body).await?;
match json {
Value::Object(map) => {
for (k, v) in map {