]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Simplify HTTP logging slightly
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 3 Sep 2025 18:09:42 +0000 (20:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Sep 2025 18:21:52 +0000 (20:21 +0200)
src/ccache/storage/remote/httpstorage.cpp

index 46260f03dca4eb4e14d1d0e726cfc9407fee53c3..7d3cd2f77c835876c77db76735c7abf813d5cd44 100644 (file)
@@ -169,27 +169,13 @@ HttpStorageBackend::HttpStorageBackend(
   m_http_client.set_default_headers(default_headers);
 }
 
-void
-log_request(const char* method,
-            std::string_view redacted_url,
-            std::string_view url_path,
-            const httplib::Result& result)
-{
-  LOG("{} {}{} -> {}",
-      method,
-      redacted_url,
-      url_path,
-      result ? std::to_string(result->status) : to_string(result.error()));
-}
-
 tl::expected<std::optional<util::Bytes>, RemoteStorage::Backend::Failure>
 HttpStorageBackend::get(const Hash::Digest& key)
 {
   const auto url_path = get_entry_path(key);
   const auto result = m_http_client.Get(url_path);
-  log_request("GET", m_redacted_url, url_path, result);
 
-  if (result.error() != httplib::Error::Success || !result) {
+  if (!result || result.error() != httplib::Error::Success) {
     LOG("Failed to get {} from http storage: {} ({})",
         url_path,
         to_string(result.error()),
@@ -197,6 +183,8 @@ HttpStorageBackend::get(const Hash::Digest& key)
     return tl::unexpected(failure_from_httplib_error(result.error()));
   }
 
+  LOG("GET {}{} -> {}", m_redacted_url, url_path, result->status);
+
   if (result->status < 200 || result->status >= 300) {
     // Don't log failure if the entry doesn't exist.
     return std::nullopt;
@@ -214,9 +202,7 @@ HttpStorageBackend::put(const Hash::Digest& key,
 
   if (overwrite == Overwrite::no) {
     const auto result = m_http_client.Head(url_path);
-    log_request("HEAD", m_redacted_url, url_path, result);
-
-    if (result.error() != httplib::Error::Success || !result) {
+    if (!result || result.error() != httplib::Error::Success) {
       LOG("Failed to check for {} in http storage: {} ({})",
           url_path,
           to_string(result.error()),
@@ -224,6 +210,8 @@ HttpStorageBackend::put(const Hash::Digest& key,
       return tl::unexpected(failure_from_httplib_error(result.error()));
     }
 
+    LOG("HEAD {}{} -> {}", m_redacted_url, url_path, result->status);
+
     if (result->status >= 200 && result->status < 300) {
       LOG("Found entry {} already within http storage: status code: {}",
           url_path,
@@ -238,9 +226,8 @@ HttpStorageBackend::put(const Hash::Digest& key,
                       reinterpret_cast<const char*>(value.data()),
                       value.size(),
                       content_type);
-  log_request("PUT", m_redacted_url, url_path, result);
 
-  if (result.error() != httplib::Error::Success || !result) {
+  if (!result || result.error() != httplib::Error::Success) {
     LOG("Failed to put {} to http storage: {} ({})",
         url_path,
         to_string(result.error()),
@@ -248,6 +235,8 @@ HttpStorageBackend::put(const Hash::Digest& key,
     return tl::unexpected(failure_from_httplib_error(result.error()));
   }
 
+  LOG("PUT {}{} -> {}", m_redacted_url, url_path, result->status);
+
   if (result->status < 200 || result->status >= 300) {
     LOG("Failed to put {} to http storage: status code: {}",
         url_path,
@@ -263,9 +252,8 @@ HttpStorageBackend::remove(const Hash::Digest& key)
 {
   const auto url_path = get_entry_path(key);
   const auto result = m_http_client.Delete(url_path);
-  log_request("DELETE", m_redacted_url, url_path, result);
 
-  if (result.error() != httplib::Error::Success || !result) {
+  if (!result || result.error() != httplib::Error::Success) {
     LOG("Failed to delete {} from http storage: {} ({})",
         url_path,
         to_string(result.error()),
@@ -273,6 +261,8 @@ HttpStorageBackend::remove(const Hash::Digest& key)
     return tl::unexpected(failure_from_httplib_error(result.error()));
   }
 
+  LOG("DELETE {}{} -> {}", m_redacted_url, url_path, result->status);
+
   if (result->status < 200 || result->status >= 300) {
     LOG("Failed to delete {} from http storage: status code: {}",
         url_path,