Skip to content

Commit

Permalink
fix(main): Server doesn't respond the url if path contains query para…
Browse files Browse the repository at this point in the history
…meter

Eg: /font/fontawesome?ver=1.1

Signed-off-by: PrajwalCH <[email protected]>
  • Loading branch information
prajwalch committed Dec 28, 2023
1 parent 60d746a commit 8e95c53
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,19 @@ fn main() {
fn normalize_url(url: &str) -> String {
let mut normalized_url = String::from('/');

// Split the url into many components, skip which we don't want and use the rest to make
// full normalized url.
// Split the url into many components, skip which we don't want and use the
// rest to make full normalized url.
//
// A component roughly corresponds to a each path of url with trailing
// slash (/) and query parameter.
//
// A component roughly corresponds to a each path of url with trailing slash (/) and query parameter.
// Example: /one/two/index.html -> [/, one/, two/, index.html]
// /one/two/?search=hello -> [/, one/, two/, ?search=hello]
normalized_url.extend(url.split_inclusive('/').filter(|component| {
*component != "/" && *component != "index.html" && !component.starts_with('?')
}));
let filtered_components = url
.split_inclusive('/')
.filter(|&comp| comp != "/" && comp != "index.html" && !comp.starts_with('?'))
.map(|comp| comp.find('?').map_or(comp, |i| &comp[..i]));

normalized_url.extend(filtered_components);
normalized_url
}

0 comments on commit 8e95c53

Please sign in to comment.