From 473f022409b9abdcec0215994de6962d01cfae84 Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Sat, 16 May 2020 13:17:42 -0400 Subject: fix issue where actix was not sending a body --- ipfs-api/src/client.rs | 26 +++++++++++++++++--------- ipfs-api/src/lib.rs | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ipfs-api/src/client.rs b/ipfs-api/src/client.rs index 7716136..0cd7796 100644 --- a/ipfs-api/src/client.rs +++ b/ipfs-api/src/client.rs @@ -29,8 +29,10 @@ use hyper_tls::HttpsConnector; use parity_multiaddr::Protocol; use serde::{Deserialize, Serialize}; use serde_json; +#[cfg(feature = "actix")] +use std::time::Duration; use std::{ - fs, + fs::{self, File}, io::{Cursor, Read}, net::{IpAddr, SocketAddr}, path::{Path, PathBuf}, @@ -39,6 +41,9 @@ use tokio_util::codec::{Decoder, FramedRead}; const FILE_DESCRIPTOR_LIMIT: usize = 127; +#[cfg(feature = "actix")] +const ACTIX_REQUEST_TIMEOUT: Duration = Duration::from_secs(90); + /// Asynchronous Ipfs client. /// #[derive(Clone)] @@ -144,7 +149,7 @@ impl IpfsClient { #[cfg(feature = "hyper")] { url.parse::().map_err(From::from).and_then(move |url| { - let builder = http::Request::builder().method("POST").uri(url); + let builder = http::Request::builder().method(http::Method::POST).uri(url); let req = if let Some(form) = form { form.set_body_convert::(builder) @@ -158,12 +163,16 @@ impl IpfsClient { #[cfg(feature = "actix")] { let req = if let Some(form) = form { - self.client.post(url).content_type(form.content_type()) + self.client + .post(url) + .timeout(ACTIX_REQUEST_TIMEOUT) + .content_type(form.content_type()) + .send_body(multipart::Body::from(form)) } else { - self.client.post(url) + self.client.post(url).timeout(ACTIX_REQUEST_TIMEOUT).send() }; - Ok(req.timeout(std::time::Duration::from_secs(90))) + Ok(req) } } @@ -235,7 +244,7 @@ impl IpfsClient { } #[cfg(feature = "actix")] { - let mut res = req.send().await?; + let mut res = req.await?; let status = res.status(); let body = res.body().await?; @@ -338,8 +347,7 @@ impl IpfsClient { } #[cfg(feature = "actix")] { - req.send() - .err_into() + req.err_into() .map_ok(move |mut res| { match res.status() { StatusCode::OK => process(res).right_stream(), @@ -502,7 +510,7 @@ impl IpfsClient { let mut form = multipart::Form::default(); for (path, file_size) in paths_to_add { - let mut file = fs::File::open(&path)?; + let mut file = File::open(&path)?; let file_name = match prefix { Some(prefix) => path.strip_prefix(prefix).unwrap(), None => path.as_path(), diff --git a/ipfs-api/src/lib.rs b/ipfs-api/src/lib.rs index 716ba23..dc02e96 100644 --- a/ipfs-api/src/lib.rs +++ b/ipfs-api/src/lib.rs @@ -171,7 +171,7 @@ use hyper::{self, client::HttpConnector}; use hyper_tls::HttpsConnector; #[cfg(feature = "actix")] -pub(crate) type Request = awc::ClientRequest; +pub(crate) type Request = awc::SendClientRequest; #[cfg(feature = "hyper")] pub(crate) type Request = http::Request; -- cgit v1.2.3