| 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 8e97f553ac08b313adfc68f93eec89a42234edf0..791e15f0be0db493cdd2a0f08d30005b5fa75370 100644
|
| --- a/net/tools/quic/quic_in_memory_cache.cc
|
| +++ b/net/tools/quic/quic_in_memory_cache.cc
|
| @@ -8,6 +8,7 @@
|
| #include "base/files/file_enumerator.h"
|
| #include "base/stl_util.h"
|
| #include "base/strings/string_number_conversions.h"
|
| +#include "net/tools/flip_server/balsa_headers.h"
|
|
|
| using base::FilePath;
|
| using base::StringPiece;
|
| @@ -20,20 +21,17 @@ using std::string;
|
| namespace net {
|
| namespace tools {
|
|
|
| -std::string FLAGS_quic_in_memory_cache_dir = "/tmp/quic-data";
|
| +std::string FLAGS_quic_in_memory_cache_dir = "";
|
|
|
| namespace {
|
|
|
| // BalsaVisitor implementation (glue) which caches response bodies.
|
| -class CachingBalsaVisitor : public BalsaVisitorInterface {
|
| +class CachingBalsaVisitor : public NoOpBalsaVisitor {
|
| public:
|
| CachingBalsaVisitor() : done_framing_(false) {}
|
| virtual void ProcessBodyData(const char* input, size_t size) OVERRIDE {
|
| AppendToBody(input, size);
|
| }
|
| - virtual void ProcessTrailers(const BalsaHeaders& trailer) {
|
| - LOG(DFATAL) << "Trailers not supported.";
|
| - }
|
| virtual void MessageDone() OVERRIDE {
|
| done_framing_ = true;
|
| }
|
| @@ -43,8 +41,6 @@ class CachingBalsaVisitor : public BalsaVisitorInterface {
|
| virtual void HandleHeaderWarning(BalsaFrame* framer) OVERRIDE {
|
| UnhandledError();
|
| }
|
| - virtual void HandleTrailerError(BalsaFrame* framer) { UnhandledError(); }
|
| - virtual void HandleTrailerWarning(BalsaFrame* framer) { UnhandledError(); }
|
| virtual void HandleChunkingError(BalsaFrame* framer) OVERRIDE {
|
| UnhandledError();
|
| }
|
| @@ -54,20 +50,6 @@ class CachingBalsaVisitor : public BalsaVisitorInterface {
|
| void UnhandledError() {
|
| LOG(DFATAL) << "Unhandled error framing HTTP.";
|
| }
|
| - virtual void ProcessBodyInput(const char*, size_t) OVERRIDE {}
|
| - virtual void ProcessHeaderInput(const char*, size_t) OVERRIDE {}
|
| - virtual void ProcessTrailerInput(const char*, size_t) OVERRIDE {}
|
| - virtual void ProcessHeaders(const net::BalsaHeaders&) OVERRIDE {}
|
| - virtual void ProcessRequestFirstLine(
|
| - const char*, size_t, const char*, size_t,
|
| - const char*, size_t, const char*, size_t) OVERRIDE {}
|
| - virtual void ProcessResponseFirstLine(
|
| - const char*, size_t, const char*,
|
| - size_t, const char*, size_t, const char*, size_t) OVERRIDE {}
|
| - virtual void ProcessChunkLength(size_t) OVERRIDE {}
|
| - virtual void ProcessChunkExtensions(const char*, size_t) OVERRIDE {}
|
| - virtual void HeaderDone() OVERRIDE {}
|
| -
|
| void AppendToBody(const char* input, size_t size) {
|
| body_.append(input, size);
|
| }
|
| @@ -81,6 +63,7 @@ class CachingBalsaVisitor : public BalsaVisitorInterface {
|
|
|
| } // namespace
|
|
|
| +// static
|
| QuicInMemoryCache* QuicInMemoryCache::GetInstance() {
|
| return Singleton<QuicInMemoryCache>::get();
|
| }
|
| @@ -94,12 +77,12 @@ const QuicInMemoryCache::Response* QuicInMemoryCache::GetResponse(
|
| return it->second;
|
| }
|
|
|
| -void QuicInMemoryCache::AddOrVerifyResponse(StringPiece method,
|
| - StringPiece path,
|
| - StringPiece version,
|
| - StringPiece response_code,
|
| - StringPiece response_detail,
|
| - StringPiece body) {
|
| +void QuicInMemoryCache::AddSimpleResponse(StringPiece method,
|
| + StringPiece path,
|
| + StringPiece version,
|
| + StringPiece response_code,
|
| + StringPiece response_detail,
|
| + StringPiece body) {
|
| BalsaHeaders request_headers, response_headers;
|
| request_headers.SetRequestFirstlineFromStringPieces(method,
|
| path,
|
| @@ -110,18 +93,7 @@ void QuicInMemoryCache::AddOrVerifyResponse(StringPiece method,
|
| response_headers.AppendHeader("content-length",
|
| base::IntToString(body.length()));
|
|
|
| - // Check if response already exists and matches.
|
| - const QuicInMemoryCache::Response* cached_response =
|
| - GetResponse(request_headers);
|
| - if (cached_response == NULL) {
|
| - AddResponse(request_headers, response_headers, body);
|
| - return;
|
| - }
|
| - string cached_response_headers_str, response_headers_str;
|
| - cached_response->headers().DumpToString(&cached_response_headers_str);
|
| - response_headers.DumpToString(&response_headers_str);
|
| - CHECK_EQ(cached_response_headers_str, response_headers_str);
|
| - CHECK_EQ(cached_response->body(), body);
|
| + AddResponse(request_headers, response_headers, body);
|
| }
|
|
|
| void QuicInMemoryCache::AddResponse(const BalsaHeaders& request_headers,
|
| @@ -130,6 +102,7 @@ void QuicInMemoryCache::AddResponse(const BalsaHeaders& request_headers,
|
| LOG(INFO) << "Adding response for: " << GetKey(request_headers);
|
| if (ContainsKey(responses_, GetKey(request_headers))) {
|
| LOG(DFATAL) << "Response for given request already exists!";
|
| + return;
|
| }
|
| Response* new_response = new Response();
|
| new_response->set_headers(response_headers);
|
| @@ -137,12 +110,12 @@ void QuicInMemoryCache::AddResponse(const BalsaHeaders& request_headers,
|
| responses_[GetKey(request_headers)] = new_response;
|
| }
|
|
|
| -void QuicInMemoryCache::ResetForTests() {
|
| - STLDeleteValues(&responses_);
|
| +QuicInMemoryCache::QuicInMemoryCache() {
|
| Initialize();
|
| }
|
|
|
| -QuicInMemoryCache::QuicInMemoryCache() {
|
| +void QuicInMemoryCache::ResetForTests() {
|
| + STLDeleteValues(&responses_);
|
| Initialize();
|
| }
|
|
|
|
|