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:
parent
83bbf1973a
commit
ddde4da033
|
|
@ -998,7 +998,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dragonfly-client"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"blake3",
|
||||
|
|
@ -1069,7 +1069,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dragonfly-client-backend"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"dragonfly-api",
|
||||
"dragonfly-client-core",
|
||||
|
|
@ -1100,7 +1100,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dragonfly-client-config"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"bytesize",
|
||||
"bytesize-serde",
|
||||
|
|
@ -1126,7 +1126,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dragonfly-client-core"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"headers 0.4.0",
|
||||
"hyper 1.6.0",
|
||||
|
|
@ -1145,7 +1145,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dragonfly-client-init"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
|
@ -1163,7 +1163,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dragonfly-client-storage"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"base16ct",
|
||||
"bincode",
|
||||
|
|
@ -1193,7 +1193,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dragonfly-client-util"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"base16ct",
|
||||
"base64 0.22.1",
|
||||
|
|
@ -1606,7 +1606,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hdfs"
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
dependencies = [
|
||||
"dragonfly-client-backend",
|
||||
"dragonfly-client-core",
|
||||
|
|
|
|||
16
Cargo.toml
16
Cargo.toml
|
|
@ -12,7 +12,7 @@ members = [
|
|||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.2.21"
|
||||
version = "0.2.22"
|
||||
authors = ["The Dragonfly Developers"]
|
||||
homepage = "https://d7y.io/"
|
||||
repository = "https://github.com/dragonflyoss/client.git"
|
||||
|
|
@ -22,13 +22,13 @@ readme = "README.md"
|
|||
edition = "2021"
|
||||
|
||||
[workspace.dependencies]
|
||||
dragonfly-client = { path = "dragonfly-client", version = "0.2.21" }
|
||||
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.21" }
|
||||
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.21" }
|
||||
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.21" }
|
||||
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.21" }
|
||||
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.21" }
|
||||
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.21" }
|
||||
dragonfly-client = { path = "dragonfly-client", version = "0.2.22" }
|
||||
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.2.22" }
|
||||
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.2.22" }
|
||||
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.2.22" }
|
||||
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.2.22" }
|
||||
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.2.22" }
|
||||
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.2.22" }
|
||||
thiserror = "1.0"
|
||||
dragonfly-api = "=2.1.36"
|
||||
reqwest = { version = "0.12.4", features = [
|
||||
|
|
|
|||
|
|
@ -430,6 +430,7 @@ pub async fn https_handler(
|
|||
// Proxy the request directly to the remote server.
|
||||
if let Some(host) = request.uri().host() {
|
||||
let host = host.to_string();
|
||||
let port = request.uri().port_u16().unwrap_or(443);
|
||||
tokio::task::spawn(async move {
|
||||
match hyper::upgrade::on(request).await {
|
||||
Ok(upgraded) => {
|
||||
|
|
@ -438,6 +439,7 @@ pub async fn https_handler(
|
|||
task,
|
||||
upgraded,
|
||||
host,
|
||||
port,
|
||||
dfdaemon_download_client,
|
||||
registry_cert,
|
||||
server_ca_cert,
|
||||
|
|
@ -467,6 +469,7 @@ async fn upgraded_tunnel(
|
|||
task: Arc<Task>,
|
||||
upgraded: Upgraded,
|
||||
host: String,
|
||||
port: u16,
|
||||
dfdaemon_download_client: DfdaemonDownloadClient,
|
||||
registry_cert: Arc<Option<Vec<CertificateDer<'static>>>>,
|
||||
server_ca_cert: Arc<Option<Certificate>>,
|
||||
|
|
@ -513,6 +516,7 @@ async fn upgraded_tunnel(
|
|||
config.clone(),
|
||||
task.clone(),
|
||||
host.clone(),
|
||||
port,
|
||||
request,
|
||||
dfdaemon_download_client.clone(),
|
||||
registry_cert.clone(),
|
||||
|
|
@ -534,6 +538,7 @@ pub async fn upgraded_handler(
|
|||
config: Arc<Config>,
|
||||
task: Arc<Task>,
|
||||
host: String,
|
||||
port: u16,
|
||||
mut request: Request<hyper::body::Incoming>,
|
||||
dfdaemon_download_client: DfdaemonDownloadClient,
|
||||
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 request.uri().scheme().is_none() {
|
||||
*request.uri_mut() = format!("https://{}{}", host, request.uri())
|
||||
.parse()
|
||||
let builder = http::uri::Builder::new();
|
||||
*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)?;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue