Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(837)

Unified Diff: net/tools/quic/quic_in_memory_cache.cc

Issue 18655004: Add a quic_in_memory_cache_test data file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add virtual for SetUp(). Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.h ('k') | net/tools/quic/quic_in_memory_cache_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_in_memory_cache.cc
diff --git a/net/tools/quic/quic_in_memory_cache.cc b/net/tools/quic/quic_in_memory_cache.cc
index 5c02ca64dfb624d29da6f877c8c1e008c82adb6c..bc277c5337c166d992b57e18f80784a2de04e3c6 100644
--- a/net/tools/quic/quic_in_memory_cache.cc
+++ b/net/tools/quic/quic_in_memory_cache.cc
@@ -86,16 +86,7 @@ QuicInMemoryCache* QuicInMemoryCache::GetInstance() {
const QuicInMemoryCache::Response* QuicInMemoryCache::GetResponse(
const BalsaHeaders& request_headers) const {
- string key = GetKey(request_headers);
- StringPiece url(key);
- // Removing the leading https:// or http://.
- if (StringPieceUtils::StartsWithIgnoreCase(url, "https://")) {
- url.remove_prefix(8);
- } else if (StringPieceUtils::StartsWithIgnoreCase(url, "http://")) {
- url.remove_prefix(7);
- }
-
- ResponseMap::const_iterator it = responses_.find(url.as_string());
+ ResponseMap::const_iterator it = responses_.find(GetKey(request_headers));
if (it == responses_.end()) {
return NULL;
}
@@ -117,9 +108,14 @@ void QuicInMemoryCache::AddResponse(const BalsaHeaders& request_headers,
void QuicInMemoryCache::ResetForTests() {
STLDeleteValues(&responses_);
+ Initialize();
}
QuicInMemoryCache::QuicInMemoryCache() {
+ Initialize();
+}
+
+void QuicInMemoryCache::Initialize() {
// If there's no defined cache dir, we have no initialization to do.
if (FLAGS_quic_in_memory_cache_dir.empty()) {
LOG(WARNING) << "No cache directory found. Skipping initialization.";
@@ -207,8 +203,16 @@ QuicInMemoryCache::~QuicInMemoryCache() {
}
string QuicInMemoryCache::GetKey(const BalsaHeaders& request_headers) const {
- return request_headers.GetHeader("host").as_string() +
- request_headers.request_uri().as_string();
+ StringPiece uri = request_headers.request_uri();
+ StringPiece host;
+ if (uri[0] == '/') {
+ host = request_headers.GetHeader("host");
+ } else if (StringPieceUtils::StartsWithIgnoreCase(uri, "https://")) {
+ uri.remove_prefix(8);
+ } else if (StringPieceUtils::StartsWithIgnoreCase(uri, "http://")) {
+ uri.remove_prefix(7);
+ }
+ return host.as_string() + uri.as_string();
}
} // namespace tools
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.h ('k') | net/tools/quic/quic_in_memory_cache_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698