diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-12-04 21:01:16 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-12-10 13:37:23 +0100 |
commit | 14aa0c3259a7997d7273f3b3ce1a41af03293832 (patch) | |
tree | e70fb994aedc72ced1e2f5ec0ca0368a3e9967ef /nix-rust/src/store/binary_cache_store.rs | |
parent | a6f0bef0a77ccc2c03d85a8e5841e830e52f5642 (diff) |
Use hyper directly instead of reqwest
Diffstat (limited to 'nix-rust/src/store/binary_cache_store.rs')
-rw-r--r-- | nix-rust/src/store/binary_cache_store.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/nix-rust/src/store/binary_cache_store.rs b/nix-rust/src/store/binary_cache_store.rs index 8241dc8f5..09be4a7fd 100644 --- a/nix-rust/src/store/binary_cache_store.rs +++ b/nix-rust/src/store/binary_cache_store.rs @@ -1,16 +1,18 @@ use super::{PathInfo, Store, StorePath}; use crate::Error; +use hyper::client::Client; +use futures::stream::Concat; pub struct BinaryCacheStore { base_uri: String, - client: reqwest::r#async::Client, + client: Client<hyper::client::HttpConnector, hyper::Body>, } impl BinaryCacheStore { pub fn new(base_uri: String) -> Self { Self { base_uri, - client: reqwest::r#async::Client::new(), + client: Client::new(), } } } @@ -26,19 +28,22 @@ impl Store for BinaryCacheStore { let store_dir = self.store_dir().to_string(); Box::pin(async move { - let response = client.get(&uri).send().await?; + let response = client.get(uri.parse::<hyper::Uri>().unwrap()).await?; - if response.status() == reqwest::StatusCode::NOT_FOUND - || response.status() == reqwest::StatusCode::FORBIDDEN + if response.status() == hyper::StatusCode::NOT_FOUND + || response.status() == hyper::StatusCode::FORBIDDEN { return Err(Error::InvalidPath(path)); } - let response = response.error_for_status()?; + let mut body = response.into_body(); - let body = response.text().await?; + let mut bytes = Vec::new(); + while let Some(next) = body.next().await { + bytes.extend(next?); + } - PathInfo::parse_nar_info(&body, &store_dir) + PathInfo::parse_nar_info(std::str::from_utf8(&bytes).unwrap(), &store_dir) }) } } |