summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2021-02-08 23:18:50 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2021-02-08 23:18:50 -0500
commit970a34a00070b1481e2821d874aaf94ad0d0a0d9 (patch)
tree24bf9b7c6fe1cdd1b50fcd9a2ba3f860080fee1a
parent8057b24e6a56b92d1a7ce22b9fb5a41c599a88d5 (diff)
clippy changes; actix upgrade; hyper-rustls upgrade
-rw-r--r--ipfs-api/src/client/internal.rs46
1 files changed, 27 insertions, 19 deletions
diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs
index 9b07572..f75ce75 100644
--- a/ipfs-api/src/client/internal.rs
+++ b/ipfs-api/src/client/internal.rs
@@ -8,13 +8,12 @@
use crate::{
client::TryFromUri,
header::TRAILER,
+ multipart,
read::{JsonLineDecoder, LineDecoder, StreamReader},
request::{self, ApiRequest},
response::{self, Error},
Client, Request, Response,
};
-#[cfg(feature = "with-actix")]
-use actix_multipart::client::multipart;
use bytes::Bytes;
use futures::{future, FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
use http::{
@@ -23,13 +22,7 @@ use http::{
};
#[cfg(feature = "with-hyper")]
use hyper::{body, client::Builder};
-#[cfg(feature = "with-hyper")]
-use hyper_multipart::client::multipart;
-#[cfg(feature = "with-hyper")]
-use crate::HyperConnector;
-
use serde::{Deserialize, Serialize};
-use serde_json;
#[cfg(feature = "with-actix")]
use std::time::Duration;
use std::{
@@ -63,9 +56,14 @@ impl TryFromUri for IpfsClient {
let client = {
#[cfg(feature = "with-hyper")]
{
+ #[cfg(feature = "with-hyper-rustls")]
+ let connector = crate::HyperConnector::with_native_roots();
+ #[cfg(not(feature = "with-hyper-rustls"))]
+ let connector = crate::HyperConnector::new();
+
Builder::default()
.pool_max_idle_per_host(0)
- .build(HyperConnector::new())
+ .build(connector)
}
#[cfg(feature = "with-actix")]
{
@@ -177,7 +175,10 @@ impl IpfsClient {
}
#[cfg(feature = "with-actix")]
{
- FramedRead::new(StreamReader::new(res), decoder)
+ // FIXME: Actix compat with bytes 1.0
+ let stream = res.map_ok(|bytes| Bytes::copy_from_slice(bytes.as_ref()));
+
+ FramedRead::new(StreamReader::new(stream), decoder)
}
}
@@ -207,7 +208,8 @@ impl IpfsClient {
let status = res.status();
let body = res.body().await?;
- Ok((status, body))
+ // FIXME: Actix compat with bytes 1.0
+ Ok((status, Bytes::copy_from_slice(body.as_ref())))
}
}
@@ -317,7 +319,12 @@ impl IpfsClient {
_ => res
.body()
.map(|maybe_body| match maybe_body {
- Ok(body) => Err(Self::process_error_from_body(body)),
+ Ok(body) => {
+ // FIXME: Actix compat with bytes 1.0
+ let body = Bytes::copy_from_slice(body.as_ref());
+
+ Err(Self::process_error_from_body(body))
+ }
Err(e) => Err(e.into()),
})
.into_stream()
@@ -338,7 +345,11 @@ impl IpfsClient {
}
#[cfg(feature = "with-actix")]
{
- self.request_stream(req, |res| res.err_into())
+ self.request_stream(req, |res| {
+ // FIXME: Actix compat with bytes 1.0
+ res.map_ok(|bytes| Bytes::copy_from_slice(bytes.as_ref()))
+ .err_into()
+ })
}
}
@@ -1313,11 +1324,8 @@ impl IpfsClient {
///
#[inline]
pub async fn files_ls(&self, path: Option<&str>) -> Result<response::FilesLsResponse, Error> {
- self.files_ls_with_options(request::FilesLs {
- path: path,
- ..default()
- })
- .await
+ self.files_ls_with_options(request::FilesLs { path, ..default() })
+ .await
}
/// List directories in MFS..
@@ -1950,7 +1958,7 @@ impl IpfsClient {
pub async fn ls(&self, path: &str) -> Result<response::LsResponse, Error> {
self.request(
request::Ls {
- path: path,
+ path,
..Default::default()
},
None,