diff --git a/command/src/command.proto b/command/src/command.proto index 7ce05681a..8622f199b 100644 --- a/command/src/command.proto +++ b/command/src/command.proto @@ -395,6 +395,7 @@ message Cluster { required LoadBalancingAlgorithms load_balancing = 5 [default = ROUND_ROBIN]; optional string answer_503 = 6; optional LoadMetric load_metric = 7; + optional uint32 https_redirect_port = 8; } enum LoadBalancingAlgorithms { diff --git a/command/src/config.rs b/command/src/config.rs index bfd3236bf..3707bd9c5 100644 --- a/command/src/config.rs +++ b/command/src/config.rs @@ -789,6 +789,7 @@ pub struct FileClusterConfig { pub protocol: FileClusterProtocolConfig, pub sticky_session: Option, pub https_redirect: Option, + pub https_redirect_port: Option, #[serde(default)] pub send_proxy: Option, #[serde(default)] @@ -888,6 +889,7 @@ impl FileClusterConfig { backends: self.backends, sticky_session: self.sticky_session.unwrap_or(false), https_redirect: self.https_redirect.unwrap_or(false), + https_redirect_port: self.https_redirect_port, load_balancing: self.load_balancing, load_metric: self.load_metric, answer_503, @@ -995,6 +997,7 @@ pub struct HttpClusterConfig { pub backends: Vec, pub sticky_session: bool, pub https_redirect: bool, + pub https_redirect_port: Option, pub load_balancing: LoadBalancingAlgorithms, pub load_metric: Option, pub answer_503: Option, @@ -1006,6 +1009,7 @@ impl HttpClusterConfig { cluster_id: self.cluster_id.clone(), sticky_session: self.sticky_session, https_redirect: self.https_redirect, + https_redirect_port: self.https_redirect_port.map(|s| s as u32), proxy_protocol: None, load_balancing: self.load_balancing as i32, answer_503: self.answer_503.clone(), @@ -1065,6 +1069,7 @@ impl TcpClusterConfig { cluster_id: self.cluster_id.clone(), sticky_session: false, https_redirect: false, + https_redirect_port: None, proxy_protocol: self.proxy_protocol.map(|s| s as i32), load_balancing: self.load_balancing as i32, load_metric: self.load_metric.map(|s| s as i32), diff --git a/lib/src/protocol/kawa_h1/mod.rs b/lib/src/protocol/kawa_h1/mod.rs index dcac5fc0c..189d4c688 100644 --- a/lib/src/protocol/kawa_h1/mod.rs +++ b/lib/src/protocol/kawa_h1/mod.rs @@ -1336,11 +1336,17 @@ impl Http)) + .map(|cluster| { + ( + cluster.https_redirect, + cluster.https_redirect_port, + None::<()>, + ) + }) .unwrap_or((false, None, None)); if !is_https && https_redirect { - let port = - https_redirect_port.map_or(String::new(), |port| format!(":{port}")); + let port = https_redirect_port + .map_or(String::new(), |port| format!(":{}", port as u16)); self.set_answer(DefaultAnswer::Answer301 { location: format!("https://{host}{port}{path}"), });