From 2f938a7fdf98f4e422b48cf345e50e7cfd5d71e5 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Tue, 16 May 2023 04:27:30 +0200 Subject: [PATCH] chore(cli): Remove redundant extra http client reqwest is already used, no need for the additional http_req. Historical artifact... --- lib/cli/Cargo.toml | 2 -- lib/cli/src/commands/create_exe.rs | 31 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index f7f42396668..a8628d4ebd7 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -107,11 +107,9 @@ clap = { version = "4.2.7", default-features = false, features = [ ]} [target.'cfg(not(target_arch = "riscv64"))'.dependencies] -http_req = { version="^0.8", default-features = false, features = ["rust-tls"] } reqwest = { version = "^0.11", default-features = false, features = ["rustls-tls", "json", "multipart"] } [target.'cfg(target_arch = "riscv64")'.dependencies] -http_req = { version="^0.8", default-features = false, features = ["native-tls"] } reqwest = { version = "^0.11", default-features = false, features = ["native-tls", "json", "multipart"] } [build-dependencies] diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index df681146557..da2e840ceda 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -1985,42 +1985,45 @@ pub(super) mod utils { mod http_fetch { use anyhow::{anyhow, Context, Result}; - use http_req::{request::Request, response::StatusCode, uri::Uri}; - use std::convert::TryFrom; use std::path::Path; pub(super) fn get_release( release_version: Option, ) -> Result { - let mut writer = Vec::new(); - let uri = Uri::try_from("https://api.github.com/repos/wasmerio/wasmer/releases").unwrap(); + let uri = "https://api.github.com/repos/wasmerio/wasmer/releases"; // Increases rate-limiting in GitHub CI let auth = std::env::var("GITHUB_TOKEN"); - let mut response = Request::new(&uri); + let client = reqwest::blocking::Client::new(); + let mut req = client.get(uri); if let Ok(token) = auth { - response.header("Authorization", &format!("Bearer {token}")); + req = req.header("Authorization", &format!("Bearer {token}")); } - let response = response + let response = req .header("User-Agent", "wasmerio") .header("Accept", "application/vnd.github.v3+json") - .timeout(Some(std::time::Duration::new(30, 0))) - .send(&mut writer) + .send() .map_err(anyhow::Error::new) .context("Could not lookup wasmer repository on Github.")?; - if response.status_code() != StatusCode::new(200) { + let status = response.status(); + + let body = response + .bytes() + .map_err(anyhow::Error::new) + .context("Could not retrieve wasmer release history body")?; + + if status != reqwest::StatusCode::OK { log::warn!( "Warning: Github API replied with non-200 status code: {}. Response: {}", - response.status_code(), - String::from_utf8_lossy(&writer), + status, + String::from_utf8_lossy(&body), ); } - let v: std::result::Result = serde_json::from_reader(&*writer); - let mut response = v.map_err(anyhow::Error::new)?; + let mut response = serde_json::from_slice::(&body)?; if let Some(releases) = response.as_array_mut() { releases.retain(|r| {