Skip to content

Commit

Permalink
chore(cli): Remove redundant extra http client
Browse files Browse the repository at this point in the history
reqwest is already used, no need for the additional http_req.

Historical artifact...
  • Loading branch information
theduke committed May 16, 2023
1 parent a75db1a commit 2f938a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 0 additions & 2 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
31 changes: 17 additions & 14 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<semver::Version>,
) -> Result<serde_json::Value> {
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::Value, _> = serde_json::from_reader(&*writer);
let mut response = v.map_err(anyhow::Error::new)?;
let mut response = serde_json::from_slice::<serde_json::Value>(&body)?;

if let Some(releases) = response.as_array_mut() {
releases.retain(|r| {
Expand Down

0 comments on commit 2f938a7

Please sign in to comment.