feat(dragonfly-client/src/proxy): add port parameter to HTTPS proxy handler (#1066)

- Modified `https_handler` to extract port from URI, defaulting to 443 if not present
- Updated `upgraded_tunnel` and `upgraded_handler` to accept port parameter
- Adjusted URI construction in `upgraded_handler` to include port in HTTPS format

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2025-03-31 18:33:57 +08:00 committed by GitHub
parent 83bbf1973a
commit ddde4da033
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 18 deletions

16
Cargo.lock generated
View File

@ -998,7 +998,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client" name = "dragonfly-client"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"blake3", "blake3",
@ -1069,7 +1069,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-backend" name = "dragonfly-client-backend"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"dragonfly-api", "dragonfly-api",
"dragonfly-client-core", "dragonfly-client-core",
@ -1100,7 +1100,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-config" name = "dragonfly-client-config"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"bytesize", "bytesize",
"bytesize-serde", "bytesize-serde",
@ -1126,7 +1126,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-core" name = "dragonfly-client-core"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"headers 0.4.0", "headers 0.4.0",
"hyper 1.6.0", "hyper 1.6.0",
@ -1145,7 +1145,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-init" name = "dragonfly-client-init"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
@ -1163,7 +1163,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-storage" name = "dragonfly-client-storage"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"base16ct", "base16ct",
"bincode", "bincode",
@ -1193,7 +1193,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-util" name = "dragonfly-client-util"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"base16ct", "base16ct",
"base64 0.22.1", "base64 0.22.1",
@ -1606,7 +1606,7 @@ dependencies = [
[[package]] [[package]]
name = "hdfs" name = "hdfs"
version = "0.2.21" version = "0.2.22"
dependencies = [ dependencies = [
"dragonfly-client-backend", "dragonfly-client-backend",
"dragonfly-client-core", "dragonfly-client-core",

View File

@ -12,7 +12,7 @@ members = [
] ]
[workspace.package] [workspace.package]
version = "0.2.21" version = "0.2.22"
authors = ["The Dragonfly Developers"] authors = ["The Dragonfly Developers"]
homepage = "https://d7y.io/" homepage = "https://d7y.io/"
repository = "https://github.com/dragonflyoss/client.git" repository = "https://github.com/dragonflyoss/client.git"
@ -22,13 +22,13 @@ readme = "README.md"
edition = "2021" edition = "2021"
[workspace.dependencies] [workspace.dependencies]
dragonfly-client = { path = "dragonfly-client", version = "0.2.21" } dragonfly-client = { path = "dragonfly-client", version = "0.2.22" }
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.21" } dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.22" }
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.21" } dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.22" }
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.21" } dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.22" }
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.21" } dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.22" }
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.21" } dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.22" }
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.21" } dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.22" }
thiserror = "1.0" thiserror = "1.0"
dragonfly-api = "=2.1.36" dragonfly-api = "=2.1.36"
reqwest = { version = "0.12.4", features = [ reqwest = { version = "0.12.4", features = [

View File

@ -430,6 +430,7 @@ pub async fn https_handler(
// Proxy the request directly to the remote server. // Proxy the request directly to the remote server.
if let Some(host) = request.uri().host() { if let Some(host) = request.uri().host() {
let host = host.to_string(); let host = host.to_string();
let port = request.uri().port_u16().unwrap_or(443);
tokio::task::spawn(async move { tokio::task::spawn(async move {
match hyper::upgrade::on(request).await { match hyper::upgrade::on(request).await {
Ok(upgraded) => { Ok(upgraded) => {
@ -438,6 +439,7 @@ pub async fn https_handler(
task, task,
upgraded, upgraded,
host, host,
port,
dfdaemon_download_client, dfdaemon_download_client,
registry_cert, registry_cert,
server_ca_cert, server_ca_cert,
@ -467,6 +469,7 @@ async fn upgraded_tunnel(
task: Arc<Task>, task: Arc<Task>,
upgraded: Upgraded, upgraded: Upgraded,
host: String, host: String,
port: u16,
dfdaemon_download_client: DfdaemonDownloadClient, dfdaemon_download_client: DfdaemonDownloadClient,
registry_cert: Arc<Option<Vec<CertificateDer<'static>>>>, registry_cert: Arc<Option<Vec<CertificateDer<'static>>>>,
server_ca_cert: Arc<Option<Certificate>>, server_ca_cert: Arc<Option<Certificate>>,
@ -513,6 +516,7 @@ async fn upgraded_tunnel(
config.clone(), config.clone(),
task.clone(), task.clone(),
host.clone(), host.clone(),
port,
request, request,
dfdaemon_download_client.clone(), dfdaemon_download_client.clone(),
registry_cert.clone(), registry_cert.clone(),
@ -534,6 +538,7 @@ pub async fn upgraded_handler(
config: Arc<Config>, config: Arc<Config>,
task: Arc<Task>, task: Arc<Task>,
host: String, host: String,
port: u16,
mut request: Request<hyper::body::Incoming>, mut request: Request<hyper::body::Incoming>,
dfdaemon_download_client: DfdaemonDownloadClient, dfdaemon_download_client: DfdaemonDownloadClient,
registry_cert: Arc<Option<Vec<CertificateDer<'static>>>>, registry_cert: Arc<Option<Vec<CertificateDer<'static>>>>,
@ -558,8 +563,18 @@ pub async fn upgraded_handler(
// If the scheme is not set, set the scheme to https. // If the scheme is not set, set the scheme to https.
if request.uri().scheme().is_none() { if request.uri().scheme().is_none() {
*request.uri_mut() = format!("https://{}{}", host, request.uri()) let builder = http::uri::Builder::new();
.parse() *request.uri_mut() = builder
.scheme("https")
.authority(format!("{}:{}", host, port))
.path_and_query(
request
.uri()
.path_and_query()
.map(|v| v.as_str())
.unwrap_or("/"),
)
.build()
.or_err(ErrorType::ParseError)?; .or_err(ErrorType::ParseError)?;
} }