aboutsummaryrefslogtreecommitdiff
path: root/src/response.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/response.rs')
-rw-r--r--src/response.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/response.rs b/src/response.rs
index 91764b9..3521e99 100644
--- a/src/response.rs
+++ b/src/response.rs
@@ -291,7 +291,10 @@ For example: to proxy "gemini://fuwn.me/uptime", visit "/proxy/fuwn.me/uptime".<
));
if let Ok(plain_texts) = var("PLAIN_TEXT_ROUTE") {
- if plain_texts.split(',').any(|r| r == req.path()) {
+ if plain_texts.split(',').any(|r| {
+ path_matches_pattern(r, req.path())
+ || path_matches_pattern(r, req.path().trim_end_matches('/'))
+ }) {
return Ok(
HttpResponse::Ok().body(response.content().clone().unwrap_or_default()),
);
@@ -304,3 +307,36 @@ For example: to proxy "gemini://fuwn.me/uptime", visit "/proxy/fuwn.me/uptime".<
.body(html_context),
)
}
+
+fn path_matches_pattern(pattern: &str, path: &str) -> bool {
+ let parts: Vec<&str> = pattern.split('*').collect();
+ let mut position = 0;
+
+ if !pattern.starts_with('*') {
+ if let Some(part) = parts.first() {
+ if !path.starts_with(part) {
+ return false;
+ }
+
+ position = part.len();
+ }
+ }
+
+ for part in &parts[1..parts.len() - 1] {
+ if let Some(found_position) = path[position..].find(part) {
+ position += found_position + part.len();
+ } else {
+ return false;
+ }
+ }
+
+ if !pattern.ends_with('*') {
+ if let Some(part) = parts.last() {
+ if !path[position..].ends_with(part) {
+ return false;
+ }
+ }
+ }
+
+ true
+}