diff --git a/Cargo.lock b/Cargo.lock index 304b1adb..301172b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -766,7 +766,7 @@ dependencies = [ "objc", "rust-ini", "web-sys", - "winreg 0.10.1", + "winreg", "zbus", "zvariant", ] @@ -1014,15 +1014,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" -[[package]] -name = "encoding_rs" -version = "0.8.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" -dependencies = [ - "cfg-if", -] - [[package]] name = "entities" version = "1.0.1" @@ -1540,25 +1531,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c" -[[package]] -name = "h2" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.12", - "indexmap 2.2.5", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "h2" version = "0.4.3" @@ -1570,7 +1542,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http 1.1.0", + "http", "indexmap 2.2.5", "slab", "tokio", @@ -1684,17 +1656,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "http" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "http" version = "1.1.0" @@ -1706,17 +1667,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.0" @@ -1724,7 +1674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http 1.1.0", + "http", ] [[package]] @@ -1735,8 +1685,8 @@ checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" dependencies = [ "bytes", "futures-core", - "http 1.1.0", - "http-body 1.0.0", + "http", + "http-body", "pin-project-lite", ] @@ -1768,30 +1718,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "hyper" -version = "0.14.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.3.25", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2 0.5.6", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.2.0" @@ -1801,9 +1727,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.3", - "http 1.1.0", - "http-body 1.0.0", + "h2", + "http", + "http-body", "httparse", "httpdate", "itoa", @@ -1813,20 +1739,6 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-rustls" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" -dependencies = [ - "futures-util", - "http 0.2.12", - "hyper 0.14.28", - "rustls", - "tokio", - "tokio-rustls", -] - [[package]] name = "hyper-util" version = "0.1.3" @@ -1835,9 +1747,9 @@ checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ "bytes", "futures-util", - "http 1.1.0", - "http-body 1.0.0", - "hyper 1.2.0", + "http", + "http-body", + "hyper", "pin-project-lite", "socket2 0.5.6", "tokio", @@ -1941,7 +1853,6 @@ dependencies = [ "pollster", "pretty_assertions", "raw-window-handle", - "reqwest", "resvg", "serde", "serde_yaml", @@ -1955,6 +1866,7 @@ dependencies = [ "tracing-subscriber", "two-face", "twox-hash", + "ureq", "wgpu", "winit", "wiremock", @@ -2016,12 +1928,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "ipnet" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" - [[package]] name = "is-docker" version = "0.2.0" @@ -2427,12 +2333,6 @@ dependencies = [ "sketches-ddsketch", ] -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - [[package]] name = "miniz_oxide" version = "0.7.2" @@ -3323,49 +3223,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b" -[[package]] -name = "reqwest" -version = "0.11.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78bf93c4af7a8bb7d879d51cebe797356ff10ae8516ace542b5182d9dcac10b2" -dependencies = [ - "base64 0.21.7", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2 0.3.25", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.28", - "hyper-rustls", - "ipnet", - "js-sys", - "log", - "mime", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls", - "rustls-pemfile", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "system-configuration", - "tokio", - "tokio-rustls", - "tokio-util", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-streams", - "web-sys", - "webpki-roots", - "winreg 0.50.0", -] - [[package]] name = "resvg" version = "0.37.0" @@ -3473,32 +3330,32 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "99008d7ad0bbbea527ec27bddbc0e432c5b87d8175178cee68d2eec9c4a1813c" dependencies = [ "log", "ring", + "rustls-pki-types", "rustls-webpki", - "sct", + "subtle", + "zeroize", ] [[package]] -name = "rustls-pemfile" -version = "1.0.4" +name = "rustls-pki-types" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.7", -] +checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" [[package]] name = "rustls-webpki" -version = "0.101.7" +version = "0.102.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" dependencies = [ "ring", + "rustls-pki-types", "untrusted", ] @@ -3568,16 +3425,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "sct" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "serde" version = "1.0.197" @@ -3629,18 +3476,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "serde_yaml" version = "0.9.32" @@ -3908,6 +3743,12 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + [[package]] name = "svg_fmt" version = "0.4.1" @@ -3956,12 +3797,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "syntect" version = "5.2.0" @@ -3995,27 +3830,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "taffy" version = "0.3.18" @@ -4200,16 +4014,6 @@ dependencies = [ "syn 2.0.52", ] -[[package]] -name = "tokio-rustls" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" -dependencies = [ - "rustls", - "tokio", -] - [[package]] name = "tokio-util" version = "0.7.10" @@ -4269,12 +4073,6 @@ dependencies = [ "winnow 0.6.5", ] -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - [[package]] name = "tracing" version = "0.1.40" @@ -4501,6 +4299,23 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "ureq" +version = "2.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11f214ce18d8b2cbe84ed3aa6486ed3f5b285cf8d8fbdbce9f3f767a724adc35" +dependencies = [ + "base64 0.21.7", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "rustls-webpki", + "url", + "webpki-roots", +] + [[package]] name = "url" version = "2.5.0" @@ -4715,19 +4530,6 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" -[[package]] -name = "wasm-streams" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b65dc4c90b63b118468cf747d8bf3566c1913ef60be765b5730ead9e0a3ba129" -dependencies = [ - "futures-util", - "js-sys", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "wayland-backend" version = "0.3.3" @@ -4908,9 +4710,12 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.25.4" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" +dependencies = [ + "rustls-pki-types", +] [[package]] name = "weezl" @@ -5335,16 +5140,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "wiremock" version = "0.6.0" @@ -5356,9 +5151,9 @@ dependencies = [ "base64 0.21.7", "deadpool", "futures", - "http 1.1.0", + "http", "http-body-util", - "hyper 1.2.0", + "hyper", "hyper-util", "log", "once_cell", @@ -5555,6 +5350,12 @@ dependencies = [ "syn 2.0.52", ] +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" + [[package]] name = "zune-inflate" version = "0.2.54" diff --git a/Cargo.toml b/Cargo.toml index a31dc7bd..f226a7eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ anyhow = "1.0.81" dirs = "5.0.1" serde = { version = "1.0.197", features = ["derive"] } toml = "0.8.11" -reqwest = { version = "0.11.26", default-features = false, features = ["blocking", "json", "rustls-tls", "stream"] } notify = "6.1.1" dark-light = "1.0.0" # We only decompress our own compressed data, so disable `safe-decode` and @@ -77,6 +76,7 @@ anstyle = "1.0.6" metrics = "0.22.3" metrics-util = { version = "0.16.3", default-features = false, features = ["registry", "summary"] } parking_lot = "0.12.1" +ureq = "2.9.6" [target.'cfg(inlyne_tcp_metrics)'.dependencies] metrics-exporter-tcp = "0.9.0" diff --git a/src/image/mod.rs b/src/image/mod.rs index 6c7d2a81..fafdbd12 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -7,13 +7,16 @@ use std::path::PathBuf; use std::str::FromStr; use std::sync::{Arc, Mutex}; use std::time::Instant; -use std::{fs, io}; +use std::{ + fs, + io::{self, Read}, +}; use crate::debug_impls::{DebugBytesPrefix, DebugInline}; use crate::interpreter::ImageCallback; use crate::metrics::{histogram, HistTag}; use crate::positioner::DEFAULT_MARGIN; -use crate::utils::{self, usize_in_mib, Align, Point, Size}; +use crate::utils::{usize_in_mib, Align, Point, Size}; use anyhow::Context; use bytemuck::{Pod, Zeroable}; @@ -232,12 +235,8 @@ impl Image { let image_data = if let Ok(img_file) = fs::read(&src_path) { img_file - } else if let Ok(bytes) = utils::client() - .get(&src) - .send() - .and_then(|resp| resp.bytes()) - { - bytes.to_vec() + } else if let Ok(bytes) = http_get_image(&src) { + bytes } else { tracing::warn!("Request for image from {} failed", src_path.display()); return; @@ -382,6 +381,26 @@ impl Image { } } +pub fn http_get_image(url: &str) -> anyhow::Result> { + const USER_AGENT: &str = concat!( + "inlyne ", + env!("CARGO_PKG_VERSION"), + " https://github.com/trimental/inlyne" + ); + + const LIMIT: usize = 20 * 1_024 * 1_024; + + let resp = ureq::get(url).set("User-Agent", USER_AGENT).call()?; + let len = resp + .header("Content-Length") + .and_then(|len| len.parse::().ok()); + let mut body = Vec::with_capacity(len.unwrap_or(0).clamp(0, LIMIT)); + resp.into_reader() + .take(u64::try_from(LIMIT).unwrap()) + .read_to_end(&mut body)?; + Ok(body) +} + #[repr(C)] #[derive(Clone, Copy, Pod, Zeroable, Debug)] pub struct ImageVertex { diff --git a/src/utils.rs b/src/utils.rs index b18485fa..d5bf39d1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,7 +9,6 @@ use comrak::adapters::SyntaxHighlighterAdapter; use comrak::plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder}; use comrak::{markdown_to_html_with_plugins, ComrakOptions}; use indexmap::IndexMap; -use reqwest::blocking::Client; use serde::Deserialize; use syntect::highlighting::{Theme as SyntectTheme, ThemeSet as SyntectThemeSet}; use syntect::parsing::SyntaxSet; @@ -55,15 +54,6 @@ fn root_filepath_to_vcs_dir(path: &Path) -> Option { } } -pub fn client() -> Client { - const USER_AGENT: &str = concat!( - "inlyne ", - env!("CARGO_PKG_VERSION"), - " https://github.com/trimental/inlyne" - ); - Client::builder().user_agent(USER_AGENT).build().unwrap() -} - pub(crate) fn default() -> T { Default::default() }