diff options
-rw-r--r-- | net/http/http_cache.cc | 5 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 28 |
2 files changed, 28 insertions, 5 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index bf067db..a45c1ba 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -1470,9 +1470,8 @@ bool HttpCache::WriteResponseInfo(disk_cache::Entry* disk_entry, // Generate a key that can be used inside the cache. std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) { - std::string url = request->url.spec(); - if (request->url.has_ref()) - url.erase(url.find_last_of('#')); + // Strip out the reference, username, and password sections of the URL. + std::string url = HttpUtil::SpecForRequest(request->url); DCHECK(mode_ != DISABLE); if (mode_ == NORMAL) { diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index 05c8920..2d67676 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -33,7 +33,7 @@ class MockDiskEntry : public disk_cache::Entry, : test_mode_(0), doomed_(false), sparse_(false) { } - MockDiskEntry(const std::string& key) + explicit MockDiskEntry(const std::string& key) : key_(key), doomed_(false), sparse_(false) { // // 'key' is prefixed with an identifier if it corresponds to a cached POST. @@ -1175,7 +1175,7 @@ TEST(HttpCache, DISABLED_ConditionalizedRequestUpdatesCache) { EXPECT_EQ(0, cache.disk_cache()->open_count()); EXPECT_EQ(1, cache.disk_cache()->create_count()); - // Request |kUrl| a second first time. Now |kNetResponse1| it is in the HTTP + // Request |kUrl| a second time. Now |kNetResponse1| it is in the HTTP // cache, so we don't hit the network. kUnexpectedResponse.AssignTo(&mock_network_response); // Network mock. @@ -1229,6 +1229,30 @@ TEST(HttpCache, DISABLED_ConditionalizedRequestUpdatesCache) { RemoveMockTransaction(&mock_network_response); } +TEST(HttpCache, UrlContainingHash) { + MockHttpCache cache; + + // Do a typical GET request -- should write an entry into our cache. + MockTransaction trans(kTypicalGET_Transaction); + RunTransactionTest(cache.http_cache(), trans); + + EXPECT_EQ(1, cache.network_layer()->transaction_count()); + EXPECT_EQ(0, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); + + // Request the same URL, but this time with a reference section (hash). + // Since the cache key strips the hash sections, this should be a cache hit. + std::string url_with_hash = std::string(trans.url) + "#multiple#hashes"; + trans.url = url_with_hash.c_str(); + trans.load_flags = net::LOAD_ONLY_FROM_CACHE; + + RunTransactionTest(cache.http_cache(), trans); + + EXPECT_EQ(1, cache.network_layer()->transaction_count()); + EXPECT_EQ(1, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); +} + TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) { MockHttpCache cache; |