♻️ Simple & Efficient Gemini-to-HTTP Proxy fuwn.net
proxy gemini-protocol protocol gemini http rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(response): PLAIN_TEXT_ROUTES wildcard matching

Fuwn 4c29f506 cbf61405

+42 -3
+1 -1
.env.example
··· 5 5 # KEEP_GEMINI_DOMAIN=fuwn.me 6 6 # PROXY_BY_DEFAULT=true 7 7 FAVICON_EXTERNAL=https://host.fuwn.me/8te8lw0lxm03.webp 8 - PLAIN_TEXT_ROUTE=/robots.txt 8 + PLAIN_TEXT_ROUTE=/robots.txt,*.xml
+4 -1
Configuration.md
··· 88 88 89 89 A comma-separated list of paths to treat as plain text routes 90 90 91 + These patterns do not support regular expressions, but do support the use of `*` 92 + as a wildcard. 93 + 91 94 ```dotenv 92 - PLAIN_TEXT_ROUTE=/robots.txt,/license.txt 95 + PLAIN_TEXT_ROUTE=/robots.txt,/license.txt,*.xml 93 96 ``` 94 97 95 98 ## `MATHJAX`
+37 -1
src/response.rs
··· 291 291 )); 292 292 293 293 if let Ok(plain_texts) = var("PLAIN_TEXT_ROUTE") { 294 - if plain_texts.split(',').any(|r| r == req.path()) { 294 + if plain_texts.split(',').any(|r| { 295 + path_matches_pattern(r, req.path()) 296 + || path_matches_pattern(r, req.path().trim_end_matches('/')) 297 + }) { 295 298 return Ok( 296 299 HttpResponse::Ok().body(response.content().clone().unwrap_or_default()), 297 300 ); ··· 304 307 .body(html_context), 305 308 ) 306 309 } 310 + 311 + fn path_matches_pattern(pattern: &str, path: &str) -> bool { 312 + let parts: Vec<&str> = pattern.split('*').collect(); 313 + let mut position = 0; 314 + 315 + if !pattern.starts_with('*') { 316 + if let Some(part) = parts.first() { 317 + if !path.starts_with(part) { 318 + return false; 319 + } 320 + 321 + position = part.len(); 322 + } 323 + } 324 + 325 + for part in &parts[1..parts.len() - 1] { 326 + if let Some(found_position) = path[position..].find(part) { 327 + position += found_position + part.len(); 328 + } else { 329 + return false; 330 + } 331 + } 332 + 333 + if !pattern.ends_with('*') { 334 + if let Some(part) = parts.last() { 335 + if !path[position..].ends_with(part) { 336 + return false; 337 + } 338 + } 339 + } 340 + 341 + true 342 + }