From d2c48afc6e58a7670bfaf1cae46a951d95e0cea4 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 22 May 2019 13:24:33 +0200 Subject: [PATCH] src/client/http_client.rs: code cleanup --- src/client/http_client.rs | 50 ++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/client/http_client.rs b/src/client/http_client.rs index 1d2fab18..afeb9c93 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -330,6 +330,30 @@ impl HttpClient { Box::new(login_future) } + fn api_response(response: Response) -> impl Future { + + let status = response.status(); + + response + .into_body() + .concat2() + .map_err(Error::from) + .and_then(move |data| { + + let text = String::from_utf8(data.to_vec()).unwrap(); + if status.is_success() { + if text.len() > 0 { + let value: Value = serde_json::from_str(&text)?; + Ok(value) + } else { + Ok(Value::Null) + } + } else { + bail!("HTTP Error {}: {}", status, text); + } + }) + } + fn api_request( client: Client>, req: Request @@ -337,29 +361,7 @@ impl HttpClient { client.request(req) .map_err(Error::from) - .and_then(|resp| { - - let status = resp.status(); - - resp - .into_body() - .concat2() - .map_err(Error::from) - .and_then(move |data| { - - let text = String::from_utf8(data.to_vec()).unwrap(); - if status.is_success() { - if text.len() > 0 { - let value: Value = serde_json::from_str(&text)?; - Ok(value) - } else { - Ok(Value::Null) - } - } else { - bail!("HTTP Error {}: {}", status, text); - } - }) - }) + .and_then(Self::api_response) } pub fn request_builder(server: &str, method: &str, path: &str, data: Option) -> Result, Error> { @@ -550,7 +552,7 @@ impl BackupClient { //upload_pxar(h2, known_chunks, &dir_path, wid).unwrap() Self::upload_stream(h2_3, wid, stream, known_chunks.clone()) - .and_then(move |size| { + .and_then(move |_size| { Self::h2post(h2_4, "dynamic_close", Some(json!({ "wid": wid }))) }) .map(|_| ())