From b81b59fc0a4df4190a3022389566350f7bdcc6c3 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Wed, 19 Jul 2023 21:27:03 +0200 Subject: [PATCH] Get rid of remove_path_prefix, it's not useful --- src/domain/settings.rs | 50 -------------------------------- src/domain/store.rs | 2 -- src/service/http/tpl/domain.html | 14 ++------- src/service/util.rs | 6 ---- 4 files changed, 2 insertions(+), 70 deletions(-) diff --git a/src/domain/settings.rs b/src/domain/settings.rs index 3112b11..18156ae 100644 --- a/src/domain/settings.rs +++ b/src/domain/settings.rs @@ -14,7 +14,6 @@ pub struct Settings { #[serde(flatten)] pub origin_descr: origin::Descr, - pub remove_path_prefix: Option, pub add_path_prefix: Option, } @@ -25,31 +24,6 @@ impl Settings { Ok(h.finalize().encode_hex::()) } - fn remove_path_prefix<'path, 'prefix>( - path: borrow::Cow<'path, str>, - prefix: &'prefix str, - ) -> borrow::Cow<'path, str> { - if prefix.len() == 0 { - return path; - } - - let mut prefix = prefix.trim_end_matches('/'); - prefix = prefix.trim_start_matches('/'); - - let mut stripped_path = path.trim_start_matches('/'); - - if !stripped_path.starts_with(prefix) { - return path; - } - - stripped_path = stripped_path.strip_prefix(prefix).unwrap(); - if stripped_path.len() == 0 { - return borrow::Cow::Borrowed("/"); - } - - borrow::Cow::Owned(stripped_path.to_string()) - } - fn add_path_prefix<'path, 'prefix>( path: borrow::Cow<'path, str>, prefix: &'prefix str, @@ -73,10 +47,6 @@ impl Settings { pub fn process_path<'a>(&self, path: &'a str) -> borrow::Cow<'a, str> { let mut path = borrow::Cow::Borrowed(path); - if let Some(ref prefix) = self.remove_path_prefix { - path = Self::remove_path_prefix(path, prefix); - } - if let Some(ref prefix) = self.add_path_prefix { path = Self::add_path_prefix(path, prefix); } @@ -90,26 +60,6 @@ mod tests { use super::*; use std::borrow; - #[test] - fn remove_path_prefix() { - let assert_remove = |want: &str, path: &str, prefix: &str| { - assert_eq!( - want, - Settings::remove_path_prefix(borrow::Cow::Borrowed(path), prefix).as_ref(), - ) - }; - - assert_remove("/bar", "/foo/bar", "/foo"); - assert_remove("/foo/bar", "/foo/bar", "/baz"); - assert_remove("/bar", "/foo/bar", "/foo/"); - assert_remove("/bar", "/foo/bar", "/foo///"); - assert_remove("/", "/", "/"); - assert_remove("/", "/foo/bar/", "/foo/bar"); - assert_remove("/", "/foo/bar", "/foo/bar"); - assert_remove("/", "/foo/bar", "/foo/bar///"); - assert_remove("/bar", "/bar", ""); - } - #[test] fn add_path_prefix() { let assert_add = |want: &str, path: &str, prefix: &str| { diff --git a/src/domain/store.rs b/src/domain/store.rs index bc0297f..016f87f 100644 --- a/src/domain/store.rs +++ b/src/domain/store.rs @@ -181,7 +181,6 @@ mod tests { url: "bar".to_string(), branch_name: "baz".to_string(), }, - remove_path_prefix: None, add_path_prefix: None, }; @@ -205,7 +204,6 @@ mod tests { url: "BAR".to_string(), branch_name: "BAZ".to_string(), }, - remove_path_prefix: None, add_path_prefix: None, }; diff --git a/src/service/http/tpl/domain.html b/src/service/http/tpl/domain.html index 9ad1a58..92779c1 100644 --- a/src/service/http/tpl/domain.html +++ b/src/service/http/tpl/domain.html @@ -51,23 +51,13 @@ automatically updated too!

Advanced Settings -

- -

diff --git a/src/service/util.rs b/src/service/util.rs index 7e5929b..d12855c 100644 --- a/src/service/util.rs +++ b/src/service/util.rs @@ -15,10 +15,6 @@ pub struct FlatDomainSettings { domain_setting_origin_descr_proxy_url: Option, - #[serde(default)] - #[serde_as(as = "NoneAsEmptyString")] - domain_setting_remove_path_prefix: Option, - #[serde(default)] #[serde_as(as = "NoneAsEmptyString")] domain_setting_add_path_prefix: Option, @@ -43,7 +39,6 @@ impl TryFrom for domain::Settings { Ok(Self { origin_descr, - remove_path_prefix: v.domain_setting_remove_path_prefix, add_path_prefix: v.domain_setting_add_path_prefix, }) } @@ -68,7 +63,6 @@ impl TryFrom for FlatDomainSettings { } } - res.domain_setting_remove_path_prefix = v.remove_path_prefix; res.domain_setting_add_path_prefix = v.add_path_prefix; Ok(res)