diff --git a/AK/Debug.h.in b/AK/Debug.h.in index 71203358874..55af25817eb 100644 --- a/AK/Debug.h.in +++ b/AK/Debug.h.in @@ -106,6 +106,10 @@ # cmakedefine01 HTML_SCRIPT_DEBUG #endif +#ifndef HTTP_DISK_CACHE_DEBUG +# cmakedefine01 HTTP_DISK_CACHE_DEBUG +#endif + #ifndef HTTP_MEMORY_CACHE_DEBUG # cmakedefine01 HTTP_MEMORY_CACHE_DEBUG #endif diff --git a/Libraries/LibHTTP/Cache/CacheEntry.cpp b/Libraries/LibHTTP/Cache/CacheEntry.cpp index 25b9f2a549c..1acbea572cc 100644 --- a/Libraries/LibHTTP/Cache/CacheEntry.cpp +++ b/Libraries/LibHTTP/Cache/CacheEntry.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -151,7 +152,7 @@ ErrorOr CacheEntryWriter::write_status_and_reason(u32 status_code, Optiona }(); if (result.is_error()) { - dbgln("\033[31;1mUnable to write status/reason to cache entry for\033[0m {}: {}", m_url, result.error()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mUnable to write status/reason to cache entry for\033[0m {}: {}", m_url, result.error()); remove(); close_and_destroy_cache_entry(); @@ -170,7 +171,7 @@ ErrorOr CacheEntryWriter::write_data(ReadonlyBytes data) } if (auto result = m_file->write_until_depleted(data); result.is_error()) { - dbgln("\033[31;1mUnable to write data to cache entry for\033[0m {}: {}", m_url, result.error()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mUnable to write data to cache entry for\033[0m {}: {}", m_url, result.error()); remove(); close_and_destroy_cache_entry(); @@ -192,7 +193,7 @@ ErrorOr CacheEntryWriter::flush(NonnullRefPtr response_headers m_cache_footer.header_hash = m_cache_header.hash(); if (auto result = m_file->write_value(m_cache_footer); result.is_error()) { - dbgln("\033[31;1mUnable to flush cache entry for\033[0m {}: {}", m_url, result.error()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mUnable to flush cache entry for\033[0m {}: {}", m_url, result.error()); remove(); return result.release_error(); @@ -200,7 +201,7 @@ ErrorOr CacheEntryWriter::flush(NonnullRefPtr response_headers m_index.create_entry(m_cache_key, m_url, move(response_headers), m_cache_footer.data_size, m_request_time, m_response_time); - dbgln("\033[34;1mFinished caching\033[0m {} ({} bytes)", m_url, m_cache_footer.data_size); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[34;1mFinished caching\033[0m {} ({} bytes)", m_url, m_cache_footer.data_size); return {}; } @@ -265,7 +266,7 @@ CacheEntryReader::CacheEntryReader(DiskCache& disk_cache, CacheIndex& index, u64 void CacheEntryReader::revalidation_succeeded(HeaderList const& response_headers) { - dbgln("\033[34;1mCache revalidation succeeded for\033[0m {}", m_url); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[34;1mCache revalidation succeeded for\033[0m {}", m_url); update_header_fields(m_response_headers, response_headers); m_index.update_response_headers(m_cache_key, m_response_headers); @@ -273,7 +274,7 @@ void CacheEntryReader::revalidation_succeeded(HeaderList const& response_headers void CacheEntryReader::revalidation_failed() { - dbgln("\033[33;1mCache revalidation failed for\033[0m {}", m_url); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[33;1mCache revalidation failed for\033[0m {}", m_url); remove(); close_and_destroy_cache_entry(); @@ -334,7 +335,7 @@ void CacheEntryReader::pipe_without_blocking() void CacheEntryReader::pipe_complete() { if (auto result = read_and_validate_footer(); result.is_error()) { - dbgln("\033[31;1mError validating cache entry for\033[0m {}: {}", m_url, result.error()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mError validating cache entry for\033[0m {}: {}", m_url, result.error()); remove(); if (m_on_pipe_error) @@ -351,7 +352,7 @@ void CacheEntryReader::pipe_complete() void CacheEntryReader::pipe_error(Error error) { - dbgln("\033[31;1mError transferring cache to pipe for\033[0m {}: {}", m_url, error); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mError transferring cache to pipe for\033[0m {}: {}", m_url, error); // FIXME: We may not want to actually remove the cache file for all errors. For now, let's assume the file is not // useable at this point and remove it. diff --git a/Libraries/LibHTTP/Cache/CacheIndex.cpp b/Libraries/LibHTTP/Cache/CacheIndex.cpp index 57b31c3ed6b..6fcdb12af43 100644 --- a/Libraries/LibHTTP/Cache/CacheIndex.cpp +++ b/Libraries/LibHTTP/Cache/CacheIndex.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -68,7 +69,7 @@ ErrorOr CacheIndex::create(Database::Database& database) if (cache_version != CACHE_VERSION) { if (cache_version != 0) - dbgln("\033[31;1mDisk cache version mismatch:\033[0m stored version = {}, new version = {}", cache_version, CACHE_VERSION); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mDisk cache version mismatch:\033[0m stored version = {}, new version = {}", cache_version, CACHE_VERSION); // FIXME: We should more elegantly handle minor changes, i.e. use ALTER TABLE to add fields to CacheIndex. auto delete_cache_index_table = TRY(database.prepare_statement("DROP TABLE IF EXISTS CacheIndex;"sv)); diff --git a/Libraries/LibHTTP/Cache/DiskCache.cpp b/Libraries/LibHTTP/Cache/DiskCache.cpp index e16afe86199..bb03034de18 100644 --- a/Libraries/LibHTTP/Cache/DiskCache.cpp +++ b/Libraries/LibHTTP/Cache/DiskCache.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -64,11 +65,11 @@ Variant, DiskCache::CacheHasOpenEntry> DiskCache::cr auto cache_entry = CacheEntryWriter::create(*this, m_index, cache_key, move(serialized_url), request_start_time, current_time_offset_for_testing); if (cache_entry.is_error()) { - dbgln("\033[31;1mUnable to create cache entry for\033[0m {}: {}", url, cache_entry.error()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mUnable to create cache entry for\033[0m {}: {}", url, cache_entry.error()); return Optional {}; } - dbgln("\033[32;1mCreated disk cache entry for\033[0m {}", url); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[32;1mCreated disk cache entry for\033[0m {}", url); auto* cache_entry_pointer = cache_entry.value().ptr(); m_open_cache_entries.ensure(cache_key).append(cache_entry.release_value()); @@ -89,13 +90,13 @@ Variant, DiskCache::CacheHasOpenEntry> DiskCache::op auto index_entry = m_index.find_entry(cache_key); if (!index_entry.has_value()) { - dbgln("\033[35;1mNo disk cache entry for\033[0m {}", url); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[35;1mNo disk cache entry for\033[0m {}", url); return Optional {}; } auto cache_entry = CacheEntryReader::create(*this, m_index, cache_key, index_entry->response_headers, index_entry->data_size); if (cache_entry.is_error()) { - dbgln("\033[31;1mUnable to open cache entry for\033[0m {}: {}", url, cache_entry.error()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[31;1mUnable to open cache entry for\033[0m {}: {}", url, cache_entry.error()); m_index.remove_entry(cache_key); return Optional {}; @@ -109,11 +110,11 @@ Variant, DiskCache::CacheHasOpenEntry> DiskCache::op switch (cache_lifetime_status(response_headers, freshness_lifetime, current_age)) { case CacheLifetimeStatus::Fresh: - dbgln("\033[32;1mOpened disk cache entry for\033[0m {} (lifetime={}s age={}s) ({} bytes)", url, freshness_lifetime.to_seconds(), current_age.to_seconds(), index_entry->data_size); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[32;1mOpened disk cache entry for\033[0m {} (lifetime={}s age={}s) ({} bytes)", url, freshness_lifetime.to_seconds(), current_age.to_seconds(), index_entry->data_size); break; case CacheLifetimeStatus::Expired: - dbgln("\033[33;1mCache entry expired for\033[0m {} (lifetime={}s age={}s)", url, freshness_lifetime.to_seconds(), current_age.to_seconds()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[33;1mCache entry expired for\033[0m {} (lifetime={}s age={}s)", url, freshness_lifetime.to_seconds(), current_age.to_seconds()); cache_entry.value()->remove(); return Optional {}; @@ -123,7 +124,7 @@ Variant, DiskCache::CacheHasOpenEntry> DiskCache::op if (check_if_cache_has_open_entry(request, cache_key, url, CheckReaderEntries::Yes)) return Optional {}; - dbgln("\033[36;1mMust revalidate disk cache entry for\033[0m {} (lifetime={}s age={}s)", url, freshness_lifetime.to_seconds(), current_age.to_seconds()); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[36;1mMust revalidate disk cache entry for\033[0m {} (lifetime={}s age={}s)", url, freshness_lifetime.to_seconds(), current_age.to_seconds()); cache_entry.value()->set_must_revalidate(); break; } @@ -142,7 +143,7 @@ bool DiskCache::check_if_cache_has_open_entry(CacheRequest& request, u64 cache_k for (auto const& open_entry : *open_entries) { if (is(*open_entry)) { - dbgln("\033[36;1mDeferring disk cache entry for\033[0m {} (waiting for existing writer)", url); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[36;1mDeferring disk cache entry for\033[0m {} (waiting for existing writer)", url); m_requests_waiting_completion.ensure(cache_key).append(request); return true; } @@ -150,7 +151,7 @@ bool DiskCache::check_if_cache_has_open_entry(CacheRequest& request, u64 cache_k // We allow concurrent readers unless another reader is open for revalidation. That reader will issue the network // request, which may then result in the cache entry being updated or deleted. if (check_reader_entries == CheckReaderEntries::Yes || as(*open_entry).must_revalidate()) { - dbgln("\033[36;1mDeferring disk cache entry for\033[0m {} (waiting for existing reader)", url); + dbgln_if(HTTP_DISK_CACHE_DEBUG, "\033[36;1mDeferring disk cache entry for\033[0m {} (waiting for existing reader)", url); m_requests_waiting_completion.ensure(cache_key).append(request); return true; } diff --git a/Meta/CMake/all_the_debug_macros.cmake b/Meta/CMake/all_the_debug_macros.cmake index b1a733e9601..755a795ed93 100644 --- a/Meta/CMake/all_the_debug_macros.cmake +++ b/Meta/CMake/all_the_debug_macros.cmake @@ -22,6 +22,7 @@ set(GIF_DEBUG ON) set(HEAP_DEBUG ON) set(HIGHLIGHT_FOCUSED_FRAME_DEBUG ON) set(HTML_SCRIPT_DEBUG ON) +set(HTTP_DISK_CACHE_DEBUG ON) set(HTTP_MEMORY_CACHE_DEBUG ON) set(HTTPJOB_DEBUG ON) set(HUNKS_DEBUG ON)