diff --git a/Cargo.lock b/Cargo.lock index 145c3df..753e393 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,19 +59,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "async-compression" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443ccbb270374a2b1055fc72da40e1f237809cd6bb0e97e66d264cd138473a6" -dependencies = [ - "brotli", - "futures-core", - "memchr", - "pin-project-lite", - "tokio", -] - [[package]] name = "atty" version = "0.2.14" @@ -116,17 +103,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "brotli" -version = "3.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71cb90ade945043d3d53597b2fc359bb063db8ade2bcffe7997351d0756e9d50" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", - "brotli-decompressor", -] - [[package]] name = "brotli-decompressor" version = "2.3.2" @@ -161,12 +137,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" - [[package]] name = "bzip2" version = "0.4.3" @@ -214,6 +184,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "chunked_transfer" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" + [[package]] name = "clap" version = "2.33.3" @@ -352,7 +328,7 @@ checksum = "254a67531cc22d81bf92a24358a1dfa3d3b30f8d326fed8c5780eb6f2e5c784f" dependencies = [ "cc", "vswhom", - "winreg 0.10.1", + "winreg", ] [[package]] @@ -421,6 +397,7 @@ name = "fnm" version = "1.27.0" dependencies = [ "atty", + "brotli-decompressor", "chrono", "clap", "colored", @@ -435,7 +412,6 @@ dependencies = [ "junction", "log", "pretty_assertions", - "reqwest", "semver", "serde", "serde_json", @@ -446,16 +422,12 @@ dependencies = [ "tar", "tempfile", "test-env-log", + "ureq", + "url", "xz2", "zip", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -466,71 +438,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures-channel" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" - -[[package]] -name = "futures-io" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" - -[[package]] -name = "futures-macro" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" -dependencies = [ - "autocfg", - "proc-macro-hack", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" - -[[package]] -name = "futures-task" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" - -[[package]] -name = "futures-util" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" -dependencies = [ - "autocfg", - "futures-core", - "futures-io", - "futures-macro", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", -] - [[package]] name = "getrandom" version = "0.2.3" @@ -548,25 +455,6 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" -[[package]] -name = "h2" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.11.2" @@ -591,85 +479,12 @@ dependencies = [ "libc", ] -[[package]] -name = "http" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" - -[[package]] -name = "httpdate" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" - [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "hyper" -version = "0.14.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" -dependencies = [ - "futures-util", - "hyper", - "log", - "rustls", - "tokio", - "tokio-rustls", - "webpki", -] - [[package]] name = "idna" version = "0.2.3" @@ -725,12 +540,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "ipnet" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" - [[package]] name = "itoa" version = "0.4.8" @@ -815,12 +624,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - [[package]] name = "miniz_oxide" version = "0.4.4" @@ -831,37 +634,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.7.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - -[[package]] -name = "ntapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi", -] - [[package]] name = "num-integer" version = "0.1.44" @@ -881,16 +653,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" version = "0.26.2" @@ -956,18 +718,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pin-project-lite" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.20" @@ -1016,18 +766,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" version = "1.0.29" @@ -1137,44 +875,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "reqwest" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51c732d463dd300362ffb44b7b125f299c23d2990411a4253824630ebc7467fb" -dependencies = [ - "async-compression", - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "http", - "http-body", - "hyper", - "hyper-rustls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "percent-encoding", - "pin-project-lite", - "rustls", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-rustls", - "tokio-util", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "webpki-roots", - "winreg 0.7.0", -] - [[package]] name = "ring" version = "0.16.20" @@ -1268,18 +968,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "serde_yaml" version = "0.8.21" @@ -1336,12 +1024,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad1d488a557b235fc46dae55512ffbfc429d2482b08b4d9435ab07384ca8aec" -[[package]] -name = "slab" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" - [[package]] name = "smallvec" version = "1.7.0" @@ -1370,16 +1052,6 @@ dependencies = [ "syn", ] -[[package]] -name = "socket2" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "spin" version = "0.5.2" @@ -1537,79 +1209,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "pin-project-lite", - "winapi", -] - -[[package]] -name = "tokio-rustls" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" -dependencies = [ - "rustls", - "tokio", - "webpki", -] - -[[package]] -name = "tokio-util" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - -[[package]] -name = "tracing" -version = "0.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - [[package]] name = "unicode-bidi" version = "0.3.6" @@ -1655,6 +1254,24 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "ureq" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3131cd6cb18488da91da1d10ed31e966f453c06b65bf010d35638456976a3fd7" +dependencies = [ + "base64", + "chunked_transfer", + "log", + "once_cell", + "rustls", + "serde", + "serde_json", + "url", + "webpki", + "webpki-roots", +] + [[package]] name = "url" version = "2.2.2" @@ -1705,16 +1322,6 @@ dependencies = [ "libc", ] -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" @@ -1746,18 +1353,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.78" @@ -1847,15 +1442,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "winreg" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -dependencies = [ - "winapi", -] - [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index 7b9c484..751b3ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ description = "Fast and simple Node.js version manager" serde = { version = "1.0.130", features = ["derive"] } clap = "2.33.3" structopt = "0.3.23" -reqwest = { version = "0.11.5", features = ["blocking", "json", "rustls-tls", "brotli"], default-features = false } serde_json = "1.0.68" chrono = { version = "0.4.19", features = ["serde"] } tar = "0.4.37" @@ -28,6 +27,9 @@ log = "0.4.14" env_logger = "0.9.0" atty = "0.2.14" encoding_rs_io = "0.1.7" +ureq = { version = "2.2.0", features = ["json"] } +url = "2.2.2" +brotli-decompressor = "2.3.2" [dev-dependencies] pretty_assertions = "1.0.0" @@ -43,3 +45,5 @@ embed-resource = "1.6.4" [target.'cfg(windows)'.dependencies] csv = "1.1.6" junction = "0.2.0" + +[features] diff --git a/src/archive/extract.rs b/src/archive/extract.rs index 52016ea..0db4ee4 100644 --- a/src/archive/extract.rs +++ b/src/archive/extract.rs @@ -5,7 +5,7 @@ use std::path::Path; pub enum Error { IoError(std::io::Error), ZipError(zip::result::ZipError), - HttpError(reqwest::Error), + HttpError(ureq::Error), } impl std::fmt::Display for Error { @@ -32,8 +32,8 @@ impl From for Error { } } -impl From for Error { - fn from(err: reqwest::Error) -> Self { +impl From for Error { + fn from(err: ureq::Error) -> Self { Self::HttpError(err) } } diff --git a/src/archive/tar_xz.rs b/src/archive/tar_xz.rs index 6b581b0..ae072cb 100644 --- a/src/archive/tar_xz.rs +++ b/src/archive/tar_xz.rs @@ -1,19 +1,18 @@ use super::extract::{Error, Extract}; -use reqwest::blocking::Response; -use std::path::Path; +use std::{io::Read, path::Path}; -pub struct TarXz { - response: Response, +pub struct TarXz { + response: R, } -impl TarXz { +impl TarXz { #[allow(dead_code)] - pub fn new(response: Response) -> Self { + pub fn new(response: R) -> Self { Self { response } } } -impl Extract for TarXz { +impl Extract for TarXz { fn extract_into>(self, path: P) -> Result<(), Error> { let xz_stream = xz2::read::XzDecoder::new(self.response); let mut tar_archive = tar::Archive::new(xz_stream); diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 9766eee..502e8e7 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -1,30 +1,29 @@ use super::extract::{Error, Extract}; use log::debug; -use reqwest::blocking::Response; use std::fs; -use std::io; +use std::io::{self, Read}; use std::path::Path; use tempfile::tempfile; use zip::read::ZipArchive; -pub struct Zip { - response: Response, +pub struct Zip { + response: R, } -impl Zip { +impl Zip { #[allow(dead_code)] - pub fn new(response: Response) -> Self { + pub fn new(response: R) -> Self { Self { response } } } -impl Extract for Zip { +impl Extract for Zip { fn extract_into>(mut self, path: P) -> Result<(), Error> { let path = path.as_ref(); let mut tmp_zip_file = tempfile().expect("Can't get a temporary file"); debug!("Created a temporary zip file"); - self.response.copy_to(&mut tmp_zip_file)?; + io::copy(&mut self.response, &mut tmp_zip_file)?; debug!( "Wrote zipfile successfully. Now extracting into {}.", path.display() @@ -88,9 +87,10 @@ mod tests { #[test_env_log::test] fn test_zip_extraction() { let temp_dir = tempfile::tempdir().expect("Can't create a temp directory"); - let response = - reqwest::blocking::get("https://nodejs.org/dist/v12.0.0/node-v12.0.0-win-x64.zip") - .expect("Can't make request to Node v12.0.0 zip file"); + let response = ureq::get("https://nodejs.org/dist/v12.0.0/node-v12.0.0-win-x64.zip") + .call() + .expect("Can't make request to Node v12.0.0 zip file") + .into_reader(); Zip::new(response) .extract_into(&temp_dir) .expect("Can't unzip files"); diff --git a/src/commands/install.rs b/src/commands/install.rs index 6424e66..2a670a4 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -144,7 +144,7 @@ pub enum Error { CantInferVersion, #[snafu(display("Having a hard time listing the remote versions: {}", source))] CantListRemoteVersions { - source: reqwest::Error, + source: ureq::Error, }, #[snafu(display( "Can't find a Node version that matches {} in remote", diff --git a/src/commands/ls_remote.rs b/src/commands/ls_remote.rs index 9855ef9..2c4d9f3 100644 --- a/src/commands/ls_remote.rs +++ b/src/commands/ls_remote.rs @@ -28,5 +28,5 @@ impl super::command::Command for LsRemote { #[derive(Debug, Snafu)] pub enum Error { - HttpError { source: reqwest::Error }, + HttpError { source: ureq::Error }, } diff --git a/src/config.rs b/src/config.rs index 4b80aa4..e680cc9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,6 +3,7 @@ use crate::log_level::LogLevel; use crate::path_ext::PathExt; use dirs::home_dir; use structopt::StructOpt; +use url::Url; #[derive(StructOpt, Debug)] pub struct FnmConfig { @@ -14,7 +15,7 @@ pub struct FnmConfig { global = true, hide_env_values = true )] - pub node_dist_mirror: reqwest::Url, + pub node_dist_mirror: Url, /// The root directory of fnm installations. #[structopt( @@ -62,7 +63,7 @@ pub struct FnmConfig { impl Default for FnmConfig { fn default() -> Self { Self { - node_dist_mirror: reqwest::Url::parse("https://nodejs.org/dist/").unwrap(), + node_dist_mirror: Url::parse("https://nodejs.org/dist/").unwrap(), base_dir: None, multishell_path: None, log_level: LogLevel::Info, diff --git a/src/downloader.rs b/src/downloader.rs index a5faa65..e4aede0 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -4,15 +4,15 @@ use crate::archive::{Error as ExtractError, Extract}; use crate::directory_portal::DirectoryPortal; use crate::version::Version; use log::debug; -use reqwest::Url; use snafu::{ensure, OptionExt, ResultExt, Snafu}; use std::path::Path; use std::path::PathBuf; +use url::Url; #[derive(Debug, Snafu)] pub enum Error { HttpError { - source: reqwest::Error, + source: ureq::Error, }, IoError { source: std::io::Error, @@ -69,8 +69,9 @@ fn download_url(base_url: &Url, version: &Version, arch: &Arch) -> Url { pub fn extract_archive_into>( path: P, - response: reqwest::blocking::Response, + response: ureq::Response, ) -> Result<(), Error> { + let response = response.into_reader(); #[cfg(unix)] let extractor = archive::TarXz::new(response); #[cfg(windows)] @@ -104,7 +105,7 @@ pub fn install_node_dist>( let url = download_url(node_dist_mirror, version, arch); debug!("Going to call for {}", &url); - let response = reqwest::blocking::get(url).context(HttpError)?; + let response = ureq::get(url.as_str()).call().context(HttpError)?; if response.status() == 404 { return Err(Error::VersionNotFound { diff --git a/src/remote_node_index.rs b/src/remote_node_index.rs index 26a11d9..c60dfba 100644 --- a/src/remote_node_index.rs +++ b/src/remote_node_index.rs @@ -1,5 +1,9 @@ +use std::io; + use crate::version::Version; +use brotli_decompressor::Decompressor; use serde::Deserialize; +use url::Url; mod lts_status { use serde::{Deserialize, Deserializer}; @@ -82,9 +86,31 @@ impl PartialOrd for IndexedNodeVersion { /// ```rust /// use crate::remote_node_index::list; /// ``` -pub fn list(base_url: &reqwest::Url) -> Result, reqwest::Error> { +pub fn list(base_url: &Url) -> Result, ureq::Error> { let index_json_url = format!("{}/index.json", base_url); - let mut value: Vec = reqwest::blocking::get(&index_json_url)?.json()?; + let resp = ureq::get(&index_json_url) + .set("Accept-Encoding", "br") + .call()?; + + let brotli_encoded = resp + .header("Content-Encoding") + .map(|enc| enc.eq_ignore_ascii_case("br")) + .unwrap_or_default(); + let reader = resp.into_reader(); + + let value = if brotli_encoded { + serde_json::from_reader(Decompressor::new(reader, 0)) + } else { + serde_json::from_reader(reader) + }; + + let mut value: Vec = value.map_err(|e| { + io::Error::new( + io::ErrorKind::InvalidData, + format!("failed decoding index JSON data: {}", e), + ) + })?; + value.sort(); Ok(value) } @@ -96,7 +122,7 @@ mod tests { #[test] fn test_list() { - let base_url = reqwest::Url::parse("https://nodejs.org/dist").unwrap(); + let base_url = Url::parse("https://nodejs.org/dist").unwrap(); let expected_version = Version::parse("12.0.0").unwrap(); let mut versions = list(&base_url).expect("Can't get HTTP data"); assert_eq!(