tangled
alpha
login
or
join now
fuwn.net
/
windmark
0
fork
atom
🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async
framework
gemini-protocol
protocol
gemini
rust
0
fork
atom
overview
issues
pulls
pipelines
refactor(router): Manually implement trailing slash clipper
fuwn.net
8 months ago
47df6e61
1b511ad3
verified
This commit was signed with the committer's
known signature
.
fuwn.net
SSH Key Fingerprint:
SHA256:VPdFPyPbd6JkoMyWUdZ/kkTcIAt3sxjXD2XSAZ7FYC4=
+31
-5
2 changed files
expand all
collapse all
unified
split
src
router.rs
utilities.rs
+4
-5
src/router.rs
reviewed
···
49
49
},
50
50
module::{AsyncModule, Module},
51
51
response::Response,
52
52
+
utilities,
52
53
};
53
54
54
55
macro_rules! block {
···
384
385
#[allow(
385
386
clippy::too_many_lines,
386
387
clippy::needless_pass_by_ref_mut,
387
387
-
clippy::significant_drop_in_scrutinee
388
388
+
clippy::significant_drop_in_scrutinee,
389
389
+
clippy::cognitive_complexity
388
390
)]
389
391
async fn handle(
390
392
&mut self,
···
418
420
}
419
421
420
422
let fixed_path = if self.fix_path {
421
421
-
self
422
422
-
.routes
423
423
-
.fix_path(url.path())
424
424
-
.unwrap_or_else(|| url.path().to_string())
423
423
+
utilities::normalize_path_slashes(url.path())
425
424
} else {
426
425
url.path().to_string()
427
426
};
+27
src/utilities.rs
reviewed
···
40
40
.map(|(k, v)| (k.to_string(), v.to_string()))
41
41
.collect()
42
42
}
43
43
+
44
44
+
/// Normalizes a path by removing all trailing slashes, unless it's the root
45
45
+
/// path "/".
46
46
+
///
47
47
+
/// # Examples
48
48
+
///
49
49
+
/// ```rust
50
50
+
/// assert_eq!(
51
51
+
/// windmark::utilities::normalize_path_slashes("/foo///"),
52
52
+
/// "/foo"
53
53
+
/// );
54
54
+
/// assert_eq!(windmark::utilities::normalize_path_slashes("/foo/"), "/foo");
55
55
+
/// assert_eq!(windmark::utilities::normalize_path_slashes("/foo"), "/foo");
56
56
+
/// assert_eq!(windmark::utilities::normalize_path_slashes("/"), "/");
57
57
+
/// ```
58
58
+
#[must_use]
59
59
+
pub fn normalize_path_slashes(path: &str) -> String {
60
60
+
if path == "/" {
61
61
+
return "/".to_string();
62
62
+
}
63
63
+
64
64
+
if path.ends_with('/') {
65
65
+
path.trim_end_matches('/').to_string()
66
66
+
} else {
67
67
+
path.to_string()
68
68
+
}
69
69
+
}