aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-01-04 18:22:42 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-01-04 18:22:42 +0100
commit22487ceddfd3b8d0641601874e0f19143da38699 (patch)
tree7ece0e10d6c416b4864149ba23f2a66018fe5788
parent6ccfbb298631e0176d587fe17f736dd2100b38b2 (diff)
downloadgarage-22487ceddfd3b8d0641601874e0f19143da38699.tar.gz
garage-22487ceddfd3b8d0641601874e0f19143da38699.zip
move Redirect::compute_target to standalone function in web_server.rs
-rw-r--r--src/model/bucket_table.rs25
-rw-r--r--src/web/web_server.rs29
2 files changed, 26 insertions, 28 deletions
diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs
index eba89e9b..b6daab75 100644
--- a/src/model/bucket_table.rs
+++ b/src/model/bucket_table.rs
@@ -85,31 +85,6 @@ mod v08 {
pub replace_key: Option<String>,
}
- impl Redirect {
- pub fn compute_target(&self, suffix: Option<&str>) -> String {
- let mut res = String::new();
- if let Some(hostname) = &self.hostname {
- if let Some(protocol) = &self.protocol {
- res.push_str(protocol);
- res.push_str("://");
- } else {
- res.push_str("//");
- }
- res.push_str(hostname);
- }
- res.push('/');
- if let Some(replace_key_prefix) = &self.replace_key_prefix {
- res.push_str(replace_key_prefix);
- if let Some(suffix) = suffix {
- res.push_str(suffix)
- }
- } else if let Some(replace_key) = &self.replace_key {
- res.push_str(replace_key)
- }
- res
- }
- }
-
#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
pub struct CorsRule {
pub id: Option<String>,
diff --git a/src/web/web_server.rs b/src/web/web_server.rs
index c497270a..bd543bb0 100644
--- a/src/web/web_server.rs
+++ b/src/web/web_server.rs
@@ -28,7 +28,7 @@ use garage_api::s3::error::{
};
use garage_api::s3::get::{handle_get_without_ctx, handle_head_without_ctx};
-use garage_model::bucket_table::RoutingRule;
+use garage_model::bucket_table::{self, RoutingRule};
use garage_model::garage::Garage;
use garage_table::*;
@@ -518,7 +518,7 @@ fn path_to_keys(
} else {
None
};
- let mut target = routing_rule.redirect.compute_target(suffix);
+ let mut target = compute_redirect_target(&routing_rule.redirect, suffix);
let query_alternative_key =
status_code == StatusCode::OK || status_code == StatusCode::NOT_FOUND;
let redirect_on_error =
@@ -560,7 +560,7 @@ fn path_to_keys(
}
}
} else {
- let target = routing_rule.redirect.compute_target(None);
+ let target = compute_redirect_target(&routing_rule.redirect, None);
return Ok(RoutingResult::Redirect {
url: target,
code: status_code,
@@ -601,6 +601,29 @@ const PATH_ENCODING_SET: &percent_encoding::AsciiSet = &percent_encoding::CONTRO
.add(b'{')
.add(b'}');
+fn compute_redirect_target(redirect: &bucket_table::Redirect, suffix: Option<&str>) -> String {
+ let mut res = String::new();
+ if let Some(hostname) = &redirect.hostname {
+ if let Some(protocol) = &redirect.protocol {
+ res.push_str(protocol);
+ res.push_str("://");
+ } else {
+ res.push_str("//");
+ }
+ res.push_str(hostname);
+ }
+ res.push('/');
+ if let Some(replace_key_prefix) = &redirect.replace_key_prefix {
+ res.push_str(replace_key_prefix);
+ if let Some(suffix) = suffix {
+ res.push_str(suffix)
+ }
+ } else if let Some(replace_key) = &redirect.replace_key {
+ res.push_str(replace_key)
+ }
+ res
+}
+
#[cfg(test)]
mod tests {
use super::*;