Skip to content

Commit 4102871

Browse files
committed
Add https_redirect_port on clusters
Signed-off-by: Eloi DEMOLIS <eloi.demolis@clever-cloud.com>
1 parent c9ffaae commit 4102871

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

command/src/command.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ message Cluster {
395395
required LoadBalancingAlgorithms load_balancing = 5 [default = ROUND_ROBIN];
396396
optional string answer_503 = 6;
397397
optional LoadMetric load_metric = 7;
398+
optional uint32 https_redirect_port = 8;
398399
}
399400

400401
enum LoadBalancingAlgorithms {

command/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ pub struct FileClusterConfig {
789789
pub protocol: FileClusterProtocolConfig,
790790
pub sticky_session: Option<bool>,
791791
pub https_redirect: Option<bool>,
792+
pub https_redirect_port: Option<u16>,
792793
#[serde(default)]
793794
pub send_proxy: Option<bool>,
794795
#[serde(default)]
@@ -888,6 +889,7 @@ impl FileClusterConfig {
888889
backends: self.backends,
889890
sticky_session: self.sticky_session.unwrap_or(false),
890891
https_redirect: self.https_redirect.unwrap_or(false),
892+
https_redirect_port: self.https_redirect_port,
891893
load_balancing: self.load_balancing,
892894
load_metric: self.load_metric,
893895
answer_503,
@@ -995,6 +997,7 @@ pub struct HttpClusterConfig {
995997
pub backends: Vec<BackendConfig>,
996998
pub sticky_session: bool,
997999
pub https_redirect: bool,
1000+
pub https_redirect_port: Option<u16>,
9981001
pub load_balancing: LoadBalancingAlgorithms,
9991002
pub load_metric: Option<LoadMetric>,
10001003
pub answer_503: Option<String>,
@@ -1006,6 +1009,7 @@ impl HttpClusterConfig {
10061009
cluster_id: self.cluster_id.clone(),
10071010
sticky_session: self.sticky_session,
10081011
https_redirect: self.https_redirect,
1012+
https_redirect_port: self.https_redirect_port.map(|s| s as u32),
10091013
proxy_protocol: None,
10101014
load_balancing: self.load_balancing as i32,
10111015
answer_503: self.answer_503.clone(),
@@ -1065,6 +1069,7 @@ impl TcpClusterConfig {
10651069
cluster_id: self.cluster_id.clone(),
10661070
sticky_session: false,
10671071
https_redirect: false,
1072+
https_redirect_port: None,
10681073
proxy_protocol: self.proxy_protocol.map(|s| s as i32),
10691074
load_balancing: self.load_balancing as i32,
10701075
load_metric: self.load_metric.map(|s| s as i32),

lib/src/protocol/kawa_h1/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,11 +1336,17 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
13361336
.borrow()
13371337
.clusters()
13381338
.get(cluster_id)
1339-
.map(|cluster| (cluster.https_redirect, Some(8443), None::<()>))
1339+
.map(|cluster| {
1340+
(
1341+
cluster.https_redirect,
1342+
cluster.https_redirect_port,
1343+
None::<()>,
1344+
)
1345+
})
13401346
.unwrap_or((false, None, None));
13411347
if !is_https && https_redirect {
1342-
let port =
1343-
https_redirect_port.map_or(String::new(), |port| format!(":{port}"));
1348+
let port = https_redirect_port
1349+
.map_or(String::new(), |port| format!(":{}", port as u16));
13441350
self.set_answer(DefaultAnswer::Answer301 {
13451351
location: format!("https://{host}{port}{path}"),
13461352
});

0 commit comments

Comments
 (0)