Skip to content

Commit

Permalink
Add https_redirect_port on clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Wonshtrum committed Dec 17, 2024
1 parent c9ffaae commit 4102871
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ pub struct FileClusterConfig {
pub protocol: FileClusterProtocolConfig,
pub sticky_session: Option<bool>,
pub https_redirect: Option<bool>,
pub https_redirect_port: Option<u16>,
#[serde(default)]
pub send_proxy: Option<bool>,
#[serde(default)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -995,6 +997,7 @@ pub struct HttpClusterConfig {
pub backends: Vec<BackendConfig>,
pub sticky_session: bool,
pub https_redirect: bool,
pub https_redirect_port: Option<u16>,
pub load_balancing: LoadBalancingAlgorithms,
pub load_metric: Option<LoadMetric>,
pub answer_503: Option<String>,
Expand All @@ -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(),
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 9 additions & 3 deletions lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,17 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
.borrow()
.clusters()
.get(cluster_id)
.map(|cluster| (cluster.https_redirect, Some(8443), None::<()>))
.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}"),
});
Expand Down

0 comments on commit 4102871

Please sign in to comment.