diff --git a/Cargo.lock b/Cargo.lock index 547d6db..0ac9153 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -511,6 +511,7 @@ dependencies = [ "http", "hyper", "hyper-reverse-proxy", + "hyper-trust-dns", "log", "mime_guess", "mockall", @@ -519,7 +520,7 @@ dependencies = [ "rand 0.8.5", "reqwest", "rust-embed", - "rustls", + "rustls 0.21.1", "serde", "serde_json", "serde_urlencoded", @@ -531,7 +532,7 @@ dependencies = [ "thiserror", "tls-listener", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-util", "trust-dns-client", ] @@ -1608,13 +1609,27 @@ dependencies = [ [[package]] name = "hyper-reverse-proxy" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc1af9b1b483fb9f33bd1cda26b35eacf902f0d116fcf0d56075ea5e5923b935" +version = "0.5.2-dev" +source = "git+https://github.com/felipenoris/hyper-reverse-proxy.git?rev=e73a76600ce9e51e962de5266b03be596e6c1d50#e73a76600ce9e51e962de5266b03be596e6c1d50" dependencies = [ "hyper", "lazy_static", - "unicase", + "tokio", + "tracing", +] + +[[package]] +name = "hyper-rustls" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +dependencies = [ + "http", + "hyper", + "rustls 0.20.9", + "tokio", + "tokio-rustls 0.23.4", + "webpki-roots", ] [[package]] @@ -1626,9 +1641,9 @@ dependencies = [ "futures-util", "http", "hyper", - "rustls", + "rustls 0.21.1", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", ] [[package]] @@ -1644,6 +1659,18 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "hyper-trust-dns" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0deaf08b5c5409c0c74011f696a82bdadae4c6d70b7a71edf8378b29bdd840bd" +dependencies = [ + "hyper", + "hyper-rustls 0.23.2", + "tokio", + "trust-dns-resolver", +] + [[package]] name = "iana-time-zone" version = "0.1.56" @@ -2526,7 +2553,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls", + "hyper-rustls 0.24.1", "hyper-tls", "ipnet", "js-sys", @@ -2536,14 +2563,14 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls", + "rustls 0.21.1", "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", "tokio", "tokio-native-tls", - "tokio-rustls", + "tokio-rustls 0.24.1", "tower-service", "trust-dns-resolver", "url", @@ -2633,6 +2660,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustls" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +dependencies = [ + "ring", + "sct", + "webpki", +] + [[package]] name = "rustls" version = "0.21.1" @@ -3041,7 +3079,7 @@ dependencies = [ "pin-project-lite", "thiserror", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", ] [[package]] @@ -3084,12 +3122,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.9", + "tokio", + "webpki", +] + [[package]] name = "tokio-rustls" version = "0.24.1" source = "git+https://code.betamike.com/micropelago/tokio-rustls.git?branch=start-handshake-into-inner#3d462a1d97836cdb0600f0bc69c5e3b3310f6d8c" dependencies = [ - "rustls", + "rustls 0.21.1", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 50bfc34..c02e7b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,11 +43,13 @@ env_logger = "0.10.0" serde_yaml = "0.9.22" rand = "0.8.5" reqwest = "0.11.18" -hyper-reverse-proxy = "0.5.1" +hyper-reverse-proxy = "0.5.2-dev" gemini = "0.0.5" bytes = "1.4.0" +hyper-trust-dns = "0.5.0" [patch.crates-io] # The micropelago fork of tokio-rustls allows for gemini proxying tokio-rustls = { git = "https://code.betamike.com/micropelago/tokio-rustls.git", branch = "start-handshake-into-inner" } +hyper-reverse-proxy = { git = "https://github.com/felipenoris/hyper-reverse-proxy.git", rev = "e73a76600ce9e51e962de5266b03be596e6c1d50" } diff --git a/flake.nix b/flake.nix index f813ca1..ab603ba 100644 --- a/flake.nix +++ b/flake.nix @@ -196,11 +196,15 @@ (buildSystem: targetSystem: let pkgs = mkPkgs buildSystem null; toolchain = mkToolchain buildSystem targetSystem; - # make clippy available directly - clippy = pkgs.writeShellScriptBin "clippy" ''exec cargo clippy "$@"''; in pkgs.mkShell ({ - packages = [ clippy ]; # extra packages for dev + shellHook = '' + export CARGO_HOME=$(pwd)/.cargo + + if [ -f "config-dev.yml" ]; then + export DOMANI_CONFIG_PATH=config-dev.yml + fi + ''; } // (buildEnv buildSystem targetSystem)) ); }; diff --git a/src/service/http/proxy.rs b/src/service/http/proxy.rs index f29a3d0..5357eea 100644 --- a/src/service/http/proxy.rs +++ b/src/service/http/proxy.rs @@ -1,6 +1,20 @@ use crate::error::unexpected; use std::net; +use hyper_reverse_proxy::ReverseProxy; +use hyper_trust_dns::{TrustDnsHttpConnector, TrustDnsResolver}; + +fn proxy_client() -> &'static ReverseProxy { + use std::sync::OnceLock; + static PROXY_CLIENT: OnceLock> = OnceLock::new(); + PROXY_CLIENT.get_or_init(|| { + ReverseProxy::new( + hyper::Client::builder() + .build::<_, hyper::Body>(TrustDnsResolver::default().into_http_connector()), + ) + }) +} + pub async fn serve_http_request( proxy_addr: &str, headers: &http::header::HeaderMap, @@ -24,7 +38,7 @@ pub async fn serve_http_request( ); } - match hyper_reverse_proxy::call(client_ip, proxy_addr, req).await { + match proxy_client().call(client_ip, proxy_addr, req).await { Ok(res) => Ok(res), // ProxyError doesn't actually implement Error :facepalm: so we have to format the error // manually