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

Side by Side Diff: net/tools/quic/quic_simple_server_stream.cc

Issue 2518063007: Pass QuicInMemoryCache directly instead of using a singleton. (Closed)
Patch Set: Fix Cronet compile error Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/quic/quic_simple_server_stream.h" 5 #include "net/tools/quic/quic_simple_server_stream.h"
6 6
7 #include <list> 7 #include <list>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "net/quic/core/quic_bug_tracker.h" 15 #include "net/quic/core/quic_bug_tracker.h"
16 #include "net/quic/core/quic_flags.h" 16 #include "net/quic/core/quic_flags.h"
17 #include "net/quic/core/quic_spdy_stream.h" 17 #include "net/quic/core/quic_spdy_stream.h"
18 #include "net/quic/core/spdy_utils.h" 18 #include "net/quic/core/spdy_utils.h"
19 #include "net/spdy/spdy_protocol.h" 19 #include "net/spdy/spdy_protocol.h"
20 #include "net/tools/quic/quic_in_memory_cache.h" 20 #include "net/tools/quic/quic_in_memory_cache.h"
21 #include "net/tools/quic/quic_simple_server_session.h" 21 #include "net/tools/quic/quic_simple_server_session.h"
22 22
23 using base::StringPiece; 23 using base::StringPiece;
24 using base::StringToInt; 24 using base::StringToInt;
25 using std::string; 25 using std::string;
26 26
27 namespace net { 27 namespace net {
28 28
29 QuicSimpleServerStream::QuicSimpleServerStream(QuicStreamId id, 29 QuicSimpleServerStream::QuicSimpleServerStream(
30 QuicSpdySession* session) 30 QuicStreamId id,
31 : QuicSpdyStream(id, session), content_length_(-1) {} 31 QuicSpdySession* session,
32 QuicInMemoryCache* in_memory_cache)
33 : QuicSpdyStream(id, session),
34 content_length_(-1),
35 in_memory_cache_(in_memory_cache) {}
32 36
33 QuicSimpleServerStream::~QuicSimpleServerStream() {} 37 QuicSimpleServerStream::~QuicSimpleServerStream() {}
34 38
35 void QuicSimpleServerStream::OnInitialHeadersComplete( 39 void QuicSimpleServerStream::OnInitialHeadersComplete(
36 bool fin, 40 bool fin,
37 size_t frame_len, 41 size_t frame_len,
38 const QuicHeaderList& header_list) { 42 const QuicHeaderList& header_list) {
39 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len, header_list); 43 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len, header_list);
40 if (!SpdyUtils::CopyAndValidateHeaders(header_list, &content_length_, 44 if (!SpdyUtils::CopyAndValidateHeaders(header_list, &content_length_,
41 &request_headers_)) { 45 &request_headers_)) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 DVLOG(1) << "Request headers do not contain :authority or :path."; 127 DVLOG(1) << "Request headers do not contain :authority or :path.";
124 SendErrorResponse(); 128 SendErrorResponse();
125 return; 129 return;
126 } 130 }
127 131
128 // Find response in cache. If not found, send error response. 132 // Find response in cache. If not found, send error response.
129 const QuicInMemoryCache::Response* response = nullptr; 133 const QuicInMemoryCache::Response* response = nullptr;
130 auto authority = request_headers_.find(":authority"); 134 auto authority = request_headers_.find(":authority");
131 auto path = request_headers_.find(":path"); 135 auto path = request_headers_.find(":path");
132 if (authority != request_headers_.end() && path != request_headers_.end()) { 136 if (authority != request_headers_.end() && path != request_headers_.end()) {
133 response = QuicInMemoryCache::GetInstance()->GetResponse(authority->second, 137 response = in_memory_cache_->GetResponse(authority->second, path->second);
134 path->second);
135 } 138 }
136 if (response == nullptr) { 139 if (response == nullptr) {
137 DVLOG(1) << "Response not found in cache."; 140 DVLOG(1) << "Response not found in cache.";
138 SendNotFoundResponse(); 141 SendNotFoundResponse();
139 return; 142 return;
140 } 143 }
141 144
142 if (response->response_type() == QuicInMemoryCache::CLOSE_CONNECTION) { 145 if (response->response_type() == QuicInMemoryCache::CLOSE_CONNECTION) {
143 DVLOG(1) << "Special response: closing connection."; 146 DVLOG(1) << "Special response: closing connection.";
144 CloseConnectionWithDetails(QUIC_NO_ERROR, "Toy server forcing close"); 147 CloseConnectionWithDetails(QUIC_NO_ERROR, "Toy server forcing close");
(...skipping 30 matching lines...) Expand all
175 // This behavior mirrors the HTTP/2 implementation. 178 // This behavior mirrors the HTTP/2 implementation.
176 bool is_redirection = response_code / 100 == 3; 179 bool is_redirection = response_code / 100 == 3;
177 if (response_code != 200 && !is_redirection) { 180 if (response_code != 200 && !is_redirection) {
178 LOG(WARNING) << "Response to server push request " << request_url 181 LOG(WARNING) << "Response to server push request " << request_url
179 << " result in response code " << response_code; 182 << " result in response code " << response_code;
180 Reset(QUIC_STREAM_CANCELLED); 183 Reset(QUIC_STREAM_CANCELLED);
181 return; 184 return;
182 } 185 }
183 } 186 }
184 std::list<QuicInMemoryCache::ServerPushInfo> resources = 187 std::list<QuicInMemoryCache::ServerPushInfo> resources =
185 QuicInMemoryCache::GetInstance()->GetServerPushResources(request_url); 188 in_memory_cache_->GetServerPushResources(request_url);
186 DVLOG(1) << "Found " << resources.size() << " push resources for stream " 189 DVLOG(1) << "Found " << resources.size() << " push resources for stream "
187 << id(); 190 << id();
188 191
189 if (!resources.empty()) { 192 if (!resources.empty()) {
190 QuicSimpleServerSession* session = 193 QuicSimpleServerSession* session =
191 static_cast<QuicSimpleServerSession*>(spdy_session()); 194 static_cast<QuicSimpleServerSession*>(spdy_session());
192 session->PromisePushResources(request_url, resources, id(), 195 session->PromisePushResources(request_url, resources, id(),
193 request_headers_); 196 request_headers_);
194 } 197 }
195 198
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 DVLOG(1) << "Writing trailers (fin = true): " 258 DVLOG(1) << "Writing trailers (fin = true): "
256 << response_trailers.DebugString(); 259 << response_trailers.DebugString();
257 WriteTrailers(std::move(response_trailers), nullptr); 260 WriteTrailers(std::move(response_trailers), nullptr);
258 } 261 }
259 262
260 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; 263 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad";
261 const char* const QuicSimpleServerStream::kNotFoundResponseBody = 264 const char* const QuicSimpleServerStream::kNotFoundResponseBody =
262 "file not found"; 265 "file not found";
263 266
264 } // namespace net 267 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_stream.h ('k') | net/tools/quic/quic_simple_server_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698