Skip to content
Snippets Groups Projects
Unverified Commit 11845d9f authored by Daniel García's avatar Daniel García Committed by GitHub
Browse files

Merge pull request #1061 from jjlin/use-strip-prefix

Use `strip_prefix()` instead of `trim_start_matches()` as appropriate
parents 0b04caab de70fbf8
No related branches found
No related tags found
No related merge requests found
...@@ -160,9 +160,7 @@ impl Fairing for BetterLogging { ...@@ -160,9 +160,7 @@ impl Fairing for BetterLogging {
} }
let uri = request.uri(); let uri = request.uri();
let uri_path = uri.path(); let uri_path = uri.path();
// FIXME: trim_start_matches() could result in over-trimming in pathological cases; let uri_subpath = uri_path.strip_prefix(&CONFIG.domain_path()).unwrap_or(uri_path);
// strip_prefix() would be a better option once it's stable.
let uri_subpath = uri_path.trim_start_matches(&CONFIG.domain_path());
if self.0 || LOGGED_ROUTES.iter().any(|r| uri_subpath.starts_with(r)) { if self.0 || LOGGED_ROUTES.iter().any(|r| uri_subpath.starts_with(r)) {
match uri.query() { match uri.query() {
Some(q) => info!(target: "request", "{} {}?{}", method, uri_path, &q[..q.len().min(30)]), Some(q) => info!(target: "request", "{} {}?{}", method, uri_path, &q[..q.len().min(30)]),
...@@ -175,9 +173,8 @@ impl Fairing for BetterLogging { ...@@ -175,9 +173,8 @@ impl Fairing for BetterLogging {
if !self.0 && request.method() == Method::Options { if !self.0 && request.method() == Method::Options {
return; return;
} }
// FIXME: trim_start_matches() could result in over-trimming in pathological cases; let uri_path = request.uri().path();
// strip_prefix() would be a better option once it's stable. let uri_subpath = uri_path.strip_prefix(&CONFIG.domain_path()).unwrap_or(uri_path);
let uri_subpath = request.uri().path().trim_start_matches(&CONFIG.domain_path());
if self.0 || LOGGED_ROUTES.iter().any(|r| uri_subpath.starts_with(r)) { if self.0 || LOGGED_ROUTES.iter().any(|r| uri_subpath.starts_with(r)) {
let status = response.status(); let status = response.status();
if let Some(route) = request.route() { if let Some(route) = request.route() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment