From f3754b46cf3f8cdeac77daee7d6a0322fbefcf89 Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 27 Sep 2023 21:40:47 +0100 Subject: [PATCH 1/8] Allow more minimal cargo features, tidy code, allow setting unix domain socket filename --- Cargo.lock | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 32 ++++--- src/main.rs | 35 +++++--- 3 files changed, 274 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5318e28..caa142c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -487,6 +487,22 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + [[package]] name = "cpufeatures" version = "0.2.9" @@ -604,6 +620,27 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "exr" version = "1.71.0" @@ -620,6 +657,12 @@ dependencies = [ "zune-inflate", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fdeflate" version = "0.3.0" @@ -654,6 +697,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -891,6 +949,19 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "idna" version = "0.4.0" @@ -938,9 +1009,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "ad227c3af19d4914570ad36d30409928b75967c298feb9ea1969db3a610bb14e" dependencies = [ "equivalent", "hashbrown 0.14.0", @@ -1011,6 +1082,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "lebe" version = "0.5.2" @@ -1053,6 +1130,12 @@ dependencies = [ "glob", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" + [[package]] name = "local-channel" version = "0.1.4" @@ -1172,6 +1255,24 @@ dependencies = [ "rayon", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "new_debug_unreachable" version = "1.0.4" @@ -1283,6 +1384,50 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "openssl" +version = "0.10.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" +dependencies = [ + "bitflags 2.4.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1572,10 +1717,12 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", + "hyper-tls", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -1585,6 +1732,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "tokio", + "tokio-native-tls", "tokio-rustls", "tokio-socks", "tokio-util", @@ -1659,6 +1807,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustls" version = "0.21.7" @@ -1696,6 +1857,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "schannel" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1712,6 +1882,29 @@ dependencies = [ "untrusted", ] +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.19" @@ -1900,19 +2093,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" [[package]] -name = "thiserror" -version = "1.0.48" +name = "tempfile" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", @@ -2003,6 +2209,16 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -2075,7 +2291,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.1", "serde", "serde_spanned", "toml_datetime", @@ -2172,6 +2388,12 @@ dependencies = [ "rust_hawktracer", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version-compare" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 11cdfb9..3355253 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,22 +6,34 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# Web Requests & Async Runtime +tokio = { version = "1.32.0", features = ["full"] } actix-web = "4.4.0" -image = "0.24.7" -libwebp-sys = { version = "0.9.4", optional = true } -mimalloc = "0.1.39" -once_cell = "1.18.0" +reqwest = { version = "0.11.20", features = ["stream", "brotli", "gzip", "socks"], default-features = false } qstring = "0.7.2" + +# Alternate Allocator +mimalloc = { version = "0.1.39", optional = true } + +# Transcoding Images to WebP/AVIF to save bandwidth +image = { version = "0.24.7", optional = true } +libwebp-sys = { version = "0.9.4", optional = true } ravif = { version = "0.11.3", optional = true } rgb = { version = "0.8.36", optional = true } + +once_cell = "1.18.0" regex = "1.9.5" -reqwest = { version = "0.11.20", features = ["rustls-tls", "stream", "brotli", "gzip", "socks"], default-features = false } -tokio = { version = "1.32.0", features = ["full"] } [features] -default = ["webp"] -avif = ["dep:ravif", "dep:rgb"] -webp = ["dep:libwebp-sys"] +default = ["webp", "mimalloc", "reqwest-rustls"] + +reqwest-rustls = ["reqwest/rustls-tls"] +reqwest-native-tls = ["reqwest/default-tls"] + +avif = ["dep:ravif", "dep:rgb", "dep:image"] +webp = ["dep:libwebp-sys", "dep:image"] + +mimalloc = ["dep:mimalloc"] [profile.release] -lto = true \ No newline at end of file +lto = true diff --git a/src/main.rs b/src/main.rs index f54a7e4..8bc6ddb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,21 @@ use actix_web::http::Method; use actix_web::{web, App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer}; -use mimalloc::MiMalloc; use once_cell::sync::Lazy; use qstring::QString; use regex::Regex; use reqwest::{Body, Client, Request, Url}; use std::env; use std::error::Error; -use tokio::sync::oneshot; -use tokio::task::spawn_blocking; +#[cfg(not(any(feature = "reqwest-native-tls", feature = "reqwest-rustls")))] +compile_error!("feature \"reqwest-native-tls\" or \"reqwest-rustls\" must be set for proxy to have TLS support"); + +#[cfg(any(feature = "webp", feature = "avif"))] +use tokio::{sync::oneshot, task::spawn_blocking}; + +#[cfg(feature = "mimalloc")] #[global_allocator] -static GLOBAL: MiMalloc = MiMalloc; +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; #[actix_web::main] async fn main() -> std::io::Result<()> { @@ -22,8 +26,8 @@ async fn main() -> std::io::Result<()> { App::new().default_service(web::to(index)) }); // get port from env - if env::var("UDS").is_ok() { - server.bind_uds("./socket/actix.sock")? + if let Ok(unix_socket) = env::var("BIND_UNIX") { + server.bind_uds(unix_socket)? } else { let bind = env::var("BIND").unwrap_or_else(|_| "0.0.0.0:8080".to_string()); server.bind(bind)? @@ -48,17 +52,17 @@ static CLIENT: Lazy = Lazy::new(|| { None }; - let builder = if proxy.is_some() { + + let builder = if let Some(proxy) = proxy { // proxy basic auth if let Ok(proxy_auth_user) = env::var("PROXY_USER") { let proxy_auth_pass = env::var("PROXY_PASS").unwrap_or_default(); builder.proxy( proxy - .unwrap() .basic_auth(&proxy_auth_user, &proxy_auth_pass), ) } else { - builder.proxy(proxy.unwrap()) + builder.proxy(proxy) } } else { builder @@ -133,6 +137,9 @@ async fn index(req: HttpRequest) -> Result> { return Err("No host provided".into()); } + #[cfg(any(feature = "webp", feature = "avif"))] + let disallow_image_transcoding = env::var("DISALLOW_IMAGE_TRANSCODING").is_ok(); + let rewrite = query.get("rewrite") != Some("false"); #[cfg(feature = "avif")] @@ -213,7 +220,9 @@ async fn index(req: HttpRequest) -> Result> { if rewrite { if let Some(content_type) = resp.headers().get("content-type") { #[cfg(feature = "avif")] - if content_type == "image/webp" || content_type == "image/jpeg" && avif { + if disallow_image_transcoding + && (content_type == "image/webp" || content_type == "image/jpeg" && avif) + { let resp_bytes = resp.bytes().await.unwrap(); let (tx, rx) = oneshot::channel::<(Vec, &'static str)>(); spawn_blocking(|| { @@ -235,11 +244,11 @@ async fn index(req: HttpRequest) -> Result> { .with_speed(7) .encode_rgb(buffer); - return if let Ok(res) = res { + if let Ok(res) = res { tx.send((res.avif_file.to_vec(), "image/avif")).unwrap(); } else { tx.send((resp_bytes.into(), "image/jpeg")).unwrap(); - }; + } }); let (body, content_type) = rx.await.unwrap(); response.content_type(content_type); @@ -247,7 +256,7 @@ async fn index(req: HttpRequest) -> Result> { } #[cfg(feature = "webp")] - if content_type == "image/jpeg" { + if !disallow_image_transcoding && content_type == "image/jpeg" { let resp_bytes = resp.bytes().await.unwrap(); let (tx, rx) = oneshot::channel::<(Vec, &'static str)>(); spawn_blocking(|| { From 7789af5658c50d3441b33774d8e06edc1136b89f Mon Sep 17 00:00:00 2001 From: chaos Date: Thu, 14 Sep 2023 18:41:04 +0100 Subject: [PATCH 2/8] Reformat code --- src/main.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8bc6ddb..b752dff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,15 +52,11 @@ static CLIENT: Lazy = Lazy::new(|| { None }; - let builder = if let Some(proxy) = proxy { // proxy basic auth if let Ok(proxy_auth_user) = env::var("PROXY_USER") { let proxy_auth_pass = env::var("PROXY_PASS").unwrap_or_default(); - builder.proxy( - proxy - .basic_auth(&proxy_auth_user, &proxy_auth_pass), - ) + builder.proxy(proxy.basic_auth(&proxy_auth_user, &proxy_auth_pass)) } else { builder.proxy(proxy) } From ba4a01dab4eeb59d8a561009d4106b79abe8484b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 22 Sep 2023 01:15:03 +0000 Subject: [PATCH 3/8] fix(deps): update rust crate ravif to 0.11.3 --- Cargo.lock | 55 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index caa142c..9ba848e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -522,6 +522,19 @@ dependencies = [ ] [[package]] +<<<<<<< HEAD +======= +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "crossbeam-deque" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -621,6 +634,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] +<<<<<<< HEAD name = "errno" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -642,6 +656,8 @@ dependencies = [ ] [[package]] +======= +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "exr" version = "1.71.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1082,12 +1098,6 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "lebe" version = "0.5.2" @@ -1131,12 +1141,15 @@ dependencies = [ ] [[package]] +<<<<<<< HEAD name = "linux-raw-sys" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" [[package]] +======= +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "local-channel" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1244,6 +1257,18 @@ dependencies = [ "log", "wasi", "windows-sys", +<<<<<<< HEAD +======= +] + +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom", +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) ] [[package]] @@ -1385,6 +1410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] +<<<<<<< HEAD name = "openssl" version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1429,6 +1455,8 @@ dependencies = [ ] [[package]] +======= +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "parking_lot" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1808,6 +1836,7 @@ dependencies = [ ] [[package]] +<<<<<<< HEAD name = "rustix" version = "0.38.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1821,6 +1850,8 @@ dependencies = [ ] [[package]] +======= +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "rustls" version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1858,6 +1889,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] +<<<<<<< HEAD name = "schannel" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1867,6 +1899,8 @@ dependencies = [ ] [[package]] +======= +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2093,6 +2127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" [[package]] +<<<<<<< HEAD name = "tempfile" version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2106,6 +2141,8 @@ dependencies = [ ] [[package]] +======= +>>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "thiserror" version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2388,12 +2425,6 @@ dependencies = [ "rust_hawktracer", ] -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version-compare" version = "0.1.1" From bf95377e9a56697d8b6c50b9b519a42e72c0d57b Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 27 Sep 2023 21:24:20 +0100 Subject: [PATCH 4/8] chore(deps): lock file maintenance --- Cargo.lock | 55 ++++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ba848e..caa142c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -522,19 +522,6 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD -======= -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "crossbeam-deque" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -634,7 +621,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -<<<<<<< HEAD name = "errno" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -656,8 +642,6 @@ dependencies = [ ] [[package]] -======= ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "exr" version = "1.71.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1098,6 +1082,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "lebe" version = "0.5.2" @@ -1141,15 +1131,12 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD name = "linux-raw-sys" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" [[package]] -======= ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "local-channel" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1257,18 +1244,6 @@ dependencies = [ "log", "wasi", "windows-sys", -<<<<<<< HEAD -======= -] - -[[package]] -name = "nanorand" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" -dependencies = [ - "getrandom", ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) ] [[package]] @@ -1410,7 +1385,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] -<<<<<<< HEAD name = "openssl" version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1455,8 +1429,6 @@ dependencies = [ ] [[package]] -======= ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "parking_lot" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1836,7 +1808,6 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD name = "rustix" version = "0.38.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1850,8 +1821,6 @@ dependencies = [ ] [[package]] -======= ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "rustls" version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1889,7 +1858,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] -<<<<<<< HEAD name = "schannel" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1899,8 +1867,6 @@ dependencies = [ ] [[package]] -======= ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2127,7 +2093,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" [[package]] -<<<<<<< HEAD name = "tempfile" version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2141,8 +2106,6 @@ dependencies = [ ] [[package]] -======= ->>>>>>> 88cd1e9 (fix(deps): update rust crate ravif to 0.11.3) name = "thiserror" version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2425,6 +2388,12 @@ dependencies = [ "rust_hawktracer", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version-compare" version = "0.1.1" From 70a167d34a1103dcb3d516d6101bae08ef274591 Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 27 Sep 2023 21:18:15 +0100 Subject: [PATCH 5/8] re-add compatibility with only UDS set --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index b752dff..0bd4c7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,9 +25,12 @@ async fn main() -> std::io::Result<()> { // match all requests App::new().default_service(web::to(index)) }); - // get port from env - if let Ok(unix_socket) = env::var("BIND_UNIX") { - server.bind_uds(unix_socket)? + + // get socket/port from env + // backwards compat when only UDS is set + let socket_path = env::var("BIND_UNIX").unwrap_or_else(|_| "./socket/actix.sock".to_string()); + if env::var("UDS").is_ok() { + server.bind_uds(socket_path)? } else { let bind = env::var("BIND").unwrap_or_else(|_| "0.0.0.0:8080".to_string()); server.bind(bind)? From 30c0926f2e943782f16b712b261574319e423b56 Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 27 Sep 2023 22:44:45 +0100 Subject: [PATCH 6/8] change default features for image to only build support for jpeg/webp decode as served by youtube and checked before decoding --- Cargo.lock | 142 +---------------------------------------------------- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 142 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index caa142c..2c757b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -330,12 +330,6 @@ version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" -[[package]] -name = "bit_field" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" - [[package]] name = "bitflags" version = "1.3.2" @@ -554,12 +548,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "crypto-common" version = "0.1.6" @@ -641,37 +629,12 @@ dependencies = [ "libc", ] -[[package]] -name = "exr" -version = "1.71.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "832a761f35ab3e6664babfbdc6cef35a4860e816ec3916dcfd0882954e98a8a8" -dependencies = [ - "bit_field", - "flume", - "half", - "lebe", - "miniz_oxide", - "rayon-core", - "smallvec", - "zune-inflate", -] - [[package]] name = "fastrand" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" -[[package]] -name = "fdeflate" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10" -dependencies = [ - "simd-adler32", -] - [[package]] name = "flate2" version = "1.0.27" @@ -682,15 +645,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "flume" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "spin 0.9.8", -] - [[package]] name = "fnv" version = "1.0.7" @@ -803,16 +757,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "gif" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" -dependencies = [ - "color_quant", - "weezl", -] - [[package]] name = "gimli" version = "0.28.0" @@ -844,15 +788,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" -dependencies = [ - "crunchy", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -981,14 +916,9 @@ dependencies = [ "bytemuck", "byteorder", "color_quant", - "exr", - "gif", "jpeg-decoder", "num-rational", "num-traits", - "png", - "qoi", - "tiff", ] [[package]] @@ -1088,12 +1018,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lebe" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" - [[package]] name = "libc" version = "0.2.148" @@ -1231,7 +1155,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", - "simd-adler32", ] [[package]] @@ -1498,19 +1421,6 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" -[[package]] -name = "png" -version = "0.17.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" -dependencies = [ - "bitflags 1.3.2", - "crc32fast", - "fdeflate", - "flate2", - "miniz_oxide", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1526,15 +1436,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "qoi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" -dependencies = [ - "bytemuck", -] - [[package]] name = "qstring" version = "0.7.2" @@ -1764,7 +1665,7 @@ dependencies = [ "cc", "libc", "once_cell", - "spin 0.5.2", + "spin", "untrusted", "web-sys", "winapi", @@ -1986,12 +1887,6 @@ dependencies = [ "libc", ] -[[package]] -name = "simd-adler32" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" - [[package]] name = "simd_helpers" version = "0.1.0" @@ -2042,15 +1937,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "syn" version = "1.0.109" @@ -2125,17 +2011,6 @@ dependencies = [ "syn 2.0.37", ] -[[package]] -name = "tiff" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d172b0f4d3fba17ba89811858b9d3d97f928aece846475bbda076ca46736211" -dependencies = [ - "flate2", - "jpeg-decoder", - "weezl", -] - [[package]] name = "time" version = "0.3.29" @@ -2516,12 +2391,6 @@ version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" -[[package]] -name = "weezl" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" - [[package]] name = "winapi" version = "0.3.9" @@ -2658,12 +2527,3 @@ dependencies = [ "libc", "pkg-config", ] - -[[package]] -name = "zune-inflate" -version = "0.2.54" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" -dependencies = [ - "simd-adler32", -] diff --git a/Cargo.toml b/Cargo.toml index 3355253..c9e37d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ qstring = "0.7.2" mimalloc = { version = "0.1.39", optional = true } # Transcoding Images to WebP/AVIF to save bandwidth -image = { version = "0.24.7", optional = true } +image = { version = "0.24.7", features = ["jpeg", "jpeg_rayon", "webp"], default-features = false, optional = true } libwebp-sys = { version = "0.9.4", optional = true } ravif = { version = "0.11.3", optional = true } rgb = { version = "0.8.36", optional = true } From 3d99bdd4549f361097de44eda542121f1b1a6fa7 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:00:33 +0100 Subject: [PATCH 7/8] Fix image transcoding check. --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 0bd4c7f..7f33608 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,7 +219,7 @@ async fn index(req: HttpRequest) -> Result> { if rewrite { if let Some(content_type) = resp.headers().get("content-type") { #[cfg(feature = "avif")] - if disallow_image_transcoding + if !disallow_image_transcoding && (content_type == "image/webp" || content_type == "image/jpeg" && avif) { let resp_bytes = resp.bytes().await.unwrap(); From 0edb727a0310d3ea11fd8a112ceb1eb931ea1e30 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:00:59 +0100 Subject: [PATCH 8/8] Small code improvement, --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7f33608..32e5922 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,8 +28,8 @@ async fn main() -> std::io::Result<()> { // get socket/port from env // backwards compat when only UDS is set - let socket_path = env::var("BIND_UNIX").unwrap_or_else(|_| "./socket/actix.sock".to_string()); if env::var("UDS").is_ok() { + let socket_path = env::var("BIND_UNIX").unwrap_or_else(|_| "./socket/actix.sock".to_string()); server.bind_uds(socket_path)? } else { let bind = env::var("BIND").unwrap_or_else(|_| "0.0.0.0:8080".to_string());