From 735bcff54fc7cf2bf9b7007f4f7926fed0db3ee9 Mon Sep 17 00:00:00 2001 From: Vika Date: Fri, 15 Apr 2022 07:45:55 +0300 Subject: Cargo.toml: add reqwest It's an advanced HTTP client that can do more than vanilla Hyper does. --- Cargo.lock | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 4 ++++ src/main.rs | 17 +++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a3c9c8..eba60ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1356,6 +1356,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "ipnet" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e70ee094dc02fd9c13fdad4940090f22dbd6ac7c9e7094a46cf0232a50bc7c" + [[package]] name = "isahc" version = "1.6.0" @@ -1455,6 +1461,7 @@ dependencies = [ "rand 0.8.4", "redis", "relative-path", + "reqwest", "retainer", "serde", "serde_json", @@ -2324,6 +2331,46 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "reqwest" +version = "0.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" +dependencies = [ + "async-compression", + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "ipnet", + "js-sys", + "lazy_static", + "log 0.4.14", + "mime", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-rustls", + "tokio-util", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + [[package]] name = "retainer" version = "0.2.2" @@ -2381,6 +2428,15 @@ dependencies = [ "webpki", ] +[[package]] +name = "rustls-pemfile" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360" +dependencies = [ + "base64", +] + [[package]] name = "rustversion" version = "1.0.6" @@ -2526,12 +2582,12 @@ dependencies = [ [[package]] name = "serde_urlencoded" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 0.4.8", + "itoa 1.0.1", "ryu", "serde", ] @@ -3489,3 +3545,12 @@ name = "windows_x86_64_msvc" version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f2b8c7cbd3bfdddd9ab98769f9746a7fad1bca236554cd032b78d768bc0e89f" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi 0.3.9", +] diff --git a/Cargo.toml b/Cargo.toml index 33f8c2a..8ccd0f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,3 +97,7 @@ features = ["client", "stream", "runtime"] version = "^0.23.0" default-features = false features = ["webpki-tokio", "http1", "http2", "tls12", "logging"] +[dependencies.reqwest] +version = "^0.11.10" +default-features = false +features = ["rustls-tls-webpki-roots", "gzip", "brotli", "json", "stream"] diff --git a/src/main.rs b/src/main.rs index 8e610e1..c69a6c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,6 +96,7 @@ async fn main() { } }; + // TODO remove this and see what screams to replace it with reqwest let http_client: hyper::Client>, hyper::Body> = { let builder = hyper::Client::builder(); let https = hyper_rustls::HttpsConnectorBuilder::new() @@ -107,6 +108,22 @@ async fn main() { builder.build(https) }; + // This thing handles redirects automatically but is type-incompatible with hyper::Client + // Bonus: less generics to be aware of, this thing hides its complexity + let http: reqwest::Client = { + #[allow(unused_mut)] + let mut builder = reqwest::Client::builder() + .user_agent(concat!( + env!("CARGO_PKG_NAME"), + "/", + env!("CARGO_PKG_VERSION") + )); + // TODO add a root certificate if there's an environment variable pointing at it + //builder = builder.add_root_certificate(reqwest::Certificate::from_pem(todo!())); + + builder.build().unwrap() + }; + if backend_uri.starts_with("redis") { println!("The Redis backend is deprecated."); std::process::exit(1); -- cgit 1.4.1