Skip to content

Commit

Permalink
Merge pull request #1061 from jjlin/use-strip-prefix
Browse files Browse the repository at this point in the history
Use `strip_prefix()` instead of `trim_start_matches()` as appropriate
  • Loading branch information
dani-garcia authored Jul 21, 2020
2 parents 0b04caa + de70fbf commit 11845d9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ impl Fairing for BetterLogging {
}
let uri = request.uri();
let uri_path = uri.path();
// FIXME: trim_start_matches() could result in over-trimming in pathological cases;
// strip_prefix() would be a better option once it's stable.
let uri_subpath = uri_path.trim_start_matches(&CONFIG.domain_path());
let uri_subpath = uri_path.strip_prefix(&CONFIG.domain_path()).unwrap_or(uri_path);
if self.0 || LOGGED_ROUTES.iter().any(|r| uri_subpath.starts_with(r)) {
match uri.query() {
Some(q) => info!(target: "request", "{} {}?{}", method, uri_path, &q[..q.len().min(30)]),
Expand All @@ -175,9 +173,8 @@ impl Fairing for BetterLogging {
if !self.0 && request.method() == Method::Options {
return;
}
// FIXME: trim_start_matches() could result in over-trimming in pathological cases;
// strip_prefix() would be a better option once it's stable.
let uri_subpath = request.uri().path().trim_start_matches(&CONFIG.domain_path());
let uri_path = request.uri().path();
let uri_subpath = uri_path.strip_prefix(&CONFIG.domain_path()).unwrap_or(uri_path);
if self.0 || LOGGED_ROUTES.iter().any(|r| uri_subpath.starts_with(r)) {
let status = response.status();
if let Some(route) = request.route() {
Expand Down

0 comments on commit 11845d9

Please sign in to comment.