From 36ae946655ac0e885268bd7502738412508d9ce2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Garc=C3=ADa?=
 <dani-garcia@users.noreply.github.com>
Date: Sun, 29 Dec 2019 15:29:46 +0100
Subject: [PATCH] Avoid some to_string in the request logging and include
 message to disable web vault when not found.

---
 src/main.rs |  4 +++-
 src/util.rs | 16 +++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 52a27604..13f3a843 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -225,7 +225,9 @@ fn check_web_vault() {
     let index_path = Path::new(&CONFIG.web_vault_folder()).join("index.html");
 
     if !index_path.exists() {
-        error!("Web vault is not found. To install it, please follow the steps in https://github.com/dani-garcia/bitwarden_rs/wiki/Building-binary#install-the-web-vault");
+        error!("Web vault is not found. To install it, please follow the steps in: ");
+        error!("https://github.com/dani-garcia/bitwarden_rs/wiki/Building-binary#install-the-web-vault");
+        error!("You can also set the environment variable 'WEB_VAULT_ENABLED=false' to disable it");
         exit(1);
     }
 }
diff --git a/src/util.rs b/src/util.rs
index aa3feb5e..01862f9c 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -151,11 +151,13 @@ impl Fairing for BetterLogging {
         if !self.0 && method == Method::Options {
             return;
         }
-        let mut uri = request.uri().to_string();
-        uri.truncate(50);
-
-        if self.0 || LOGGED_ROUTES.iter().any(|r| uri.starts_with(r)) {
-            info!(target: "request", "{} {}", method, uri);
+        let uri = request.uri();
+        let uri_path = uri.path();
+        if self.0 || LOGGED_ROUTES.iter().any(|r| uri_path.starts_with(r)) {
+            match uri.query() {
+                Some(q) => info!(target: "request", "{} {}?{}", method, uri_path, &q[..q.len().min(30)]),
+                None => info!(target: "request", "{} {}", method, uri_path),
+            };
         }
     }
 
@@ -163,8 +165,8 @@ impl Fairing for BetterLogging {
         if !self.0 && request.method() == Method::Options {
             return;
         }
-        let uri = request.uri().to_string();
-        if self.0 || LOGGED_ROUTES.iter().any(|r| uri.starts_with(r)) {
+        let uri_path = request.uri().path();
+        if self.0 || LOGGED_ROUTES.iter().any(|r| uri_path.starts_with(r)) {
             let status = response.status();
             if let Some(ref route) = request.route() {
                 info!(target: "response", "{} => {} {}", route, status.code, status.reason)
-- 
GitLab