| OLD | NEW |
| 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_in_memory_cache.h" | 5 #include "net/tools/quic/quic_in_memory_cache.h" |
| 6 | 6 |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 StringPiece path, | 65 StringPiece path, |
| 66 int response_code, | 66 int response_code, |
| 67 StringPiece body) { | 67 StringPiece body) { |
| 68 SpdyHeaderBlock response_headers; | 68 SpdyHeaderBlock response_headers; |
| 69 response_headers[":status"] = IntToString(response_code); | 69 response_headers[":status"] = IntToString(response_code); |
| 70 response_headers["content-length"] = | 70 response_headers["content-length"] = |
| 71 IntToString(static_cast<int>(body.length())); | 71 IntToString(static_cast<int>(body.length())); |
| 72 AddResponse(host, path, response_headers, body); | 72 AddResponse(host, path, response_headers, body); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void QuicInMemoryCache::AddBidirectionalResponse( |
| 76 StringPiece host, |
| 77 StringPiece path, |
| 78 int response_code, |
| 79 const std::vector<std::string>& body_chunks, |
| 80 const SpdyHeaderBlock& response_trailers) { |
| 81 SpdyHeaderBlock response_headers; |
| 82 response_headers[":status"] = IntToString(response_code); |
| 83 AddResponseImpl(host, path, BIDIRECTIONAL, response_headers, "", body_chunks, |
| 84 response_trailers); |
| 85 } |
| 86 |
| 75 void QuicInMemoryCache::AddSimpleResponseWithServerPushResources( | 87 void QuicInMemoryCache::AddSimpleResponseWithServerPushResources( |
| 76 StringPiece host, | 88 StringPiece host, |
| 77 StringPiece path, | 89 StringPiece path, |
| 78 int response_code, | 90 int response_code, |
| 79 StringPiece body, | 91 StringPiece body, |
| 80 list<ServerPushInfo> push_resources) { | 92 list<ServerPushInfo> push_resources) { |
| 81 AddSimpleResponse(host, path, response_code, body); | 93 AddSimpleResponse(host, path, response_code, body); |
| 82 MaybeAddServerPushResources(host, path, push_resources); | 94 MaybeAddServerPushResources(host, path, push_resources); |
| 83 } | 95 } |
| 84 | 96 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 STLDeleteValues(&responses_); | 212 STLDeleteValues(&responses_); |
| 201 } | 213 } |
| 202 | 214 |
| 203 void QuicInMemoryCache::AddResponseImpl( | 215 void QuicInMemoryCache::AddResponseImpl( |
| 204 StringPiece host, | 216 StringPiece host, |
| 205 StringPiece path, | 217 StringPiece path, |
| 206 SpecialResponseType response_type, | 218 SpecialResponseType response_type, |
| 207 const SpdyHeaderBlock& response_headers, | 219 const SpdyHeaderBlock& response_headers, |
| 208 StringPiece response_body, | 220 StringPiece response_body, |
| 209 const SpdyHeaderBlock& response_trailers) { | 221 const SpdyHeaderBlock& response_trailers) { |
| 222 std::vector<std::string> body_chunks; |
| 223 AddResponseImpl(host, path, response_type, response_headers, response_body, |
| 224 body_chunks, response_trailers); |
| 225 } |
| 226 void QuicInMemoryCache::AddResponseImpl( |
| 227 StringPiece host, |
| 228 StringPiece path, |
| 229 SpecialResponseType response_type, |
| 230 const SpdyHeaderBlock& response_headers, |
| 231 StringPiece response_body, |
| 232 const std::vector<std::string>& body_chunks, |
| 233 const SpdyHeaderBlock& response_trailers) { |
| 210 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\""; | 234 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\""; |
| 211 string key = GetKey(host, path); | 235 string key = GetKey(host, path); |
| 212 if (ContainsKey(responses_, key)) { | 236 if (ContainsKey(responses_, key)) { |
| 213 QUIC_BUG << "Response for '" << key << "' already exists!"; | 237 QUIC_BUG << "Response for '" << key << "' already exists!"; |
| 214 return; | 238 return; |
| 215 } | 239 } |
| 216 Response* new_response = new Response(); | 240 Response* new_response = new Response(); |
| 217 new_response->set_response_type(response_type); | 241 new_response->set_response_type(response_type); |
| 218 new_response->set_headers(response_headers); | 242 new_response->set_headers(response_headers); |
| 219 new_response->set_body(response_body); | 243 if (response_type != BIDIRECTIONAL) { |
| 244 CHECK(body_chunks.empty()); |
| 245 new_response->set_body(response_body); |
| 246 } else { |
| 247 new_response->SetBodyChunks(body_chunks); |
| 248 } |
| 220 new_response->set_trailers(response_trailers); | 249 new_response->set_trailers(response_trailers); |
| 221 responses_[key] = new_response; | 250 responses_[key] = new_response; |
| 222 } | 251 } |
| 223 | 252 |
| 224 string QuicInMemoryCache::GetKey(StringPiece host, StringPiece path) const { | 253 string QuicInMemoryCache::GetKey(StringPiece host, StringPiece path) const { |
| 225 return host.as_string() + path.as_string(); | 254 return host.as_string() + path.as_string(); |
| 226 } | 255 } |
| 227 | 256 |
| 228 void QuicInMemoryCache::MaybeAddServerPushResources( | 257 void QuicInMemoryCache::MaybeAddServerPushResources( |
| 229 StringPiece request_host, | 258 StringPiece request_host, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 for (auto it = resource_range.first; it != resource_range.second; ++it) { | 290 for (auto it = resource_range.first; it != resource_range.second; ++it) { |
| 262 ServerPushInfo push_resource = it->second; | 291 ServerPushInfo push_resource = it->second; |
| 263 if (push_resource.request_url.spec() == resource.request_url.spec()) { | 292 if (push_resource.request_url.spec() == resource.request_url.spec()) { |
| 264 return true; | 293 return true; |
| 265 } | 294 } |
| 266 } | 295 } |
| 267 return false; | 296 return false; |
| 268 } | 297 } |
| 269 | 298 |
| 270 } // namespace net | 299 } // namespace net |
| OLD | NEW |