diff options
| author | Fuwn <[email protected]> | 2025-06-07 13:34:17 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-06-07 13:34:17 +0000 |
| commit | 22bce5a842dc365a5a18644d0fbdcc75e6aa5d5e (patch) | |
| tree | 17f02d84656a586e826fae5c2802644a045e6b13 /src/response.rs | |
| parent | chore: Bump version patch (diff) | |
| download | september-22bce5a842dc365a5a18644d0fbdcc75e6aa5d5e.tar.xz september-22bce5a842dc365a5a18644d0fbdcc75e6aa5d5e.zip | |
feat!: Overhaul KEEP_GEMINI configuration option
Diffstat (limited to 'src/response.rs')
| -rw-r--r-- | src/response.rs | 49 |
1 files changed, 3 insertions, 46 deletions
diff --git a/src/response.rs b/src/response.rs index 1a68b08..68c1690 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,7 +1,7 @@ pub mod configuration; use { - crate::url::from_path as url_from_path, + crate::url::{from_path as url_from_path, matches_pattern}, actix_web::{Error, HttpResponse}, std::{env::var, fmt::Write, time::Instant}, }; @@ -262,8 +262,8 @@ pub async fn default( if let Ok(plain_texts) = var("PLAIN_TEXT_ROUTE") { if plain_texts.split(',').any(|r| { - path_matches_pattern(r, http_request.path()) - || path_matches_pattern(r, http_request.path().trim_end_matches('/')) + matches_pattern(r, http_request.path()) + || matches_pattern(r, http_request.path().trim_end_matches('/')) }) { return Ok(HttpResponse::Ok().body( response.content().as_ref().map_or_else(String::default, String::clone), @@ -277,46 +277,3 @@ pub async fn default( .body(html_context), ) } - -fn path_matches_pattern(pattern: &str, path: &str) -> bool { - if !pattern.contains('*') { - return path == pattern; - } - - let parts: Vec<&str> = pattern.split('*').collect(); - let mut position = if pattern.starts_with('*') { - 0 - } else { - let first = parts.first().unwrap(); - - if !path.starts_with(first) { - return false; - } - - first.len() - }; - - let mid_end = parts.len().saturating_sub(1); - - for part in &parts[1..mid_end] { - if part.is_empty() { - continue; - } - - if let Some(found) = path[position..].find(part) { - position += found + part.len(); - } else { - return false; - } - } - - if !pattern.ends_with('*') { - let last = parts.last().unwrap(); - - if !path[position..].ends_with(last) { - return false; - } - } - - true -} |