Skip to content

Commit

Permalink
Re-enable https_redirect on cluster level
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Wonshtrum committed Dec 13, 2024
1 parent 5d7e0f9 commit 2360820
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,8 @@ mod tests {

use super::*;
use crate::proto::command::{
CustomHttpAnswers, LoadBalancingParams, RequestHttpFrontend, RulePosition,
CustomHttpAnswers, LoadBalancingParams, RedirectPolicy, RedirectScheme,
RequestHttpFrontend, RulePosition,
};

#[test]
Expand Down Expand Up @@ -1724,6 +1725,8 @@ mod tests {
hostname: String::from("test.local"),
path: PathRule::prefix(String::from("/abc")),
address: SocketAddress::new_v4(0, 0, 0, 0, 8080),
redirect: Some(RedirectPolicy::Forward.into()),
redirect_scheme: Some(RedirectScheme::UseSame.into()),
..Default::default()
})
.into(),
Expand Down
23 changes: 19 additions & 4 deletions lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
&mut self,
proxy: Rc<RefCell<dyn L7Proxy>>,
) -> Result<String, RetrieveClusterError> {
let (host, uri, method) = match self.extract_route() {
let (host, path, method) = match self.extract_route() {
Ok(tuple) => tuple,
Err(cluster_error) => {
self.set_answer(DefaultAnswer::Answer400 {
Expand All @@ -1269,7 +1269,7 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
let route_result = self
.listener
.borrow()
.frontend_from_request(host, uri, method);
.frontend_from_request(host, path, method);

let route = match route_result {
Ok(route) => route,
Expand All @@ -1289,9 +1289,24 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
rewritten_host,
rewritten_path,
} => {
let host = rewritten_host.as_deref().unwrap_or(host);
let path = rewritten_path.as_deref().unwrap_or(uri);
let is_https = matches!(proxy.borrow().kind(), ListenerType::Https);
if let RouteDirection::Forward(cluster_id) = &flow {
if !is_https
&& proxy
.borrow()
.clusters()
.get(cluster_id)
.map(|cluster| cluster.https_redirect)
.unwrap_or(false)
{
self.set_answer(DefaultAnswer::Answer301 {
location: format!("https://{host}{path}"),
});
return Err(RetrieveClusterError::Redirected);
}
}
let host = rewritten_host.as_deref().unwrap_or(host);
let path = rewritten_path.as_deref().unwrap_or(path);
match flow {
RouteDirection::Forward(cluster_id) => Ok(cluster_id),
RouteDirection::Permanent(redirect_scheme) => {
Expand Down

0 comments on commit 2360820

Please sign in to comment.