Skip to content

Commit

Permalink
Merge pull request #49 from jyn514/attohttpc
Browse files Browse the repository at this point in the history
Switch from reqwest to attohttpc
  • Loading branch information
pietroalbini authored Nov 12, 2020
2 parents ccd30e7 + dd1b0ba commit 7a4ef73
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ unstable = []
unstable-toolchain-ci = []

[dependencies]
http = "0.2"
failure = "0.1.3"
futures-util = "0.3.5"
log = "0.4.6"
tokio = { version = "0.2.21", features = ["process", "time"] }
tokio = { version = "0.2.21", features = ["process", "time", "io-util", "stream", "rt-core", "rt-threaded"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
scopeguard = "1.0.0"
lazy_static = "1.0.0"
tempfile = "3.0.0"
reqwest = { version = "0.10.4", features = ["blocking"] }
attohttpc = "0.16"
flate2 = "1"
tar = "0.4.0"
percent-encoding = "2.1.0"
Expand Down
6 changes: 3 additions & 3 deletions src/crates/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ impl CrateTrait for RegistryCrate {
std::fs::create_dir_all(parent)?;
}

let mut resp = workspace
workspace
.http_client()
.get(&self.fetch_url(workspace)?)
.send()?
.error_for_status()?;
resp.copy_to(&mut BufWriter::new(File::create(&local)?))?;
.error_for_status()?
.write_to(&mut BufWriter::new(File::create(&local)?))?;

Ok(())
}
Expand Down
13 changes: 5 additions & 8 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,12 @@ impl WorkspaceBuilder {
SandboxImage::remote(DEFAULT_SANDBOX_IMAGE)?
};

let mut headers = reqwest::header::HeaderMap::new();
headers.insert(reqwest::header::USER_AGENT, self.user_agent.parse()?);
let http = reqwest::blocking::ClientBuilder::new()
.default_headers(headers)
.build()?;
let mut agent = attohttpc::Session::new();
agent.header(http::header::USER_AGENT, self.user_agent);

let mut ws = Workspace {
inner: Arc::new(WorkspaceInner {
http,
http: agent,
path: self.path,
sandbox_image,
command_timeout: self.command_timeout,
Expand All @@ -180,7 +177,7 @@ impl WorkspaceBuilder {
}

struct WorkspaceInner {
http: reqwest::blocking::Client,
http: attohttpc::Session,
path: PathBuf,
sandbox_image: SandboxImage,
command_timeout: Option<Duration>,
Expand Down Expand Up @@ -266,7 +263,7 @@ impl Workspace {
crate::toolchain::list_installed_toolchains(&self.rustup_home())
}

pub(crate) fn http_client(&self) -> &reqwest::blocking::Client {
pub(crate) fn http_client(&self) -> &attohttpc::Session {
&self.inner.http
}

Expand Down

0 comments on commit 7a4ef73

Please sign in to comment.