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_http_response_cache.h" | 5 #include "net/tools/quic/quic_http_response_cache.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_number_conversions.h" | |
14 #include "base/strings/string_util.h" | |
15 #include "base/strings/stringprintf.h" | |
16 #include "net/http/http_util.h" | 13 #include "net/http/http_util.h" |
17 #include "net/quic/core/quic_bug_tracker.h" | 14 #include "net/quic/core/quic_bug_tracker.h" |
| 15 #include "net/quic/platform/api/quic_text_utils.h" |
18 #include "net/spdy/spdy_http_utils.h" | 16 #include "net/spdy/spdy_http_utils.h" |
19 | 17 |
20 using base::FilePath; | 18 using base::FilePath; |
21 using base::IntToString; | 19 using base::IntToString; |
22 using base::StringPiece; | 20 using base::StringPiece; |
23 using std::string; | 21 using std::string; |
24 | 22 |
25 namespace net { | 23 namespace net { |
26 | 24 |
27 QuicHttpResponseCache::ServerPushInfo::ServerPushInfo( | 25 QuicHttpResponseCache::ServerPushInfo::ServerPushInfo( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 continue; | 79 continue; |
82 } | 80 } |
83 // Headers are "key: value". | 81 // Headers are "key: value". |
84 pos = line.find(": "); | 82 pos = line.find(": "); |
85 if (pos == string::npos) { | 83 if (pos == string::npos) { |
86 LOG(DFATAL) << "Headers invalid or empty, ignoring: " | 84 LOG(DFATAL) << "Headers invalid or empty, ignoring: " |
87 << file_name_.value(); | 85 << file_name_.value(); |
88 return; | 86 return; |
89 } | 87 } |
90 spdy_headers_.AppendValueOrAddHeader( | 88 spdy_headers_.AppendValueOrAddHeader( |
91 base::ToLowerASCII(line.substr(0, pos)), line.substr(pos + 2)); | 89 QuicTextUtils::ToLower(line.substr(0, pos)), line.substr(pos + 2)); |
92 } | 90 } |
93 | 91 |
94 // The connection header is prohibited in HTTP/2. | 92 // The connection header is prohibited in HTTP/2. |
95 spdy_headers_.erase("connection"); | 93 spdy_headers_.erase("connection"); |
96 | 94 |
97 // Override the URL with the X-Original-Url header, if present. | 95 // Override the URL with the X-Original-Url header, if present. |
98 auto it = spdy_headers_.find("x-original-url"); | 96 auto it = spdy_headers_.find("x-original-url"); |
99 if (it != spdy_headers_.end()) { | 97 if (it != spdy_headers_.end()) { |
100 x_original_url_ = it->second; | 98 x_original_url_ = it->second; |
101 HandleXOriginalUrl(); | 99 HandleXOriginalUrl(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 host_ = base.substr(0, path_start); | 135 host_ = base.substr(0, path_start); |
138 size_t query_start = base.find_first_of(','); | 136 size_t query_start = base.find_first_of(','); |
139 if (query_start > 0) { | 137 if (query_start > 0) { |
140 path_ = base.substr(path_start, query_start - 1); | 138 path_ = base.substr(path_start, query_start - 1); |
141 } else { | 139 } else { |
142 path_ = base.substr(path_start); | 140 path_ = base.substr(path_start); |
143 } | 141 } |
144 } | 142 } |
145 | 143 |
146 StringPiece QuicHttpResponseCache::ResourceFile::RemoveScheme(StringPiece url) { | 144 StringPiece QuicHttpResponseCache::ResourceFile::RemoveScheme(StringPiece url) { |
147 if (base::StartsWith(url, "https://", base::CompareCase::INSENSITIVE_ASCII)) { | 145 if (QuicTextUtils::StartsWith(url, "https://")) { |
148 url.remove_prefix(8); | 146 url.remove_prefix(8); |
149 } else if (base::StartsWith(url, "http://", | 147 } else if (QuicTextUtils::StartsWith(url, "http://")) { |
150 base::CompareCase::INSENSITIVE_ASCII)) { | |
151 url.remove_prefix(7); | 148 url.remove_prefix(7); |
152 } | 149 } |
153 return url; | 150 return url; |
154 } | 151 } |
155 | 152 |
156 void QuicHttpResponseCache::ResourceFile::HandleXOriginalUrl() { | 153 void QuicHttpResponseCache::ResourceFile::HandleXOriginalUrl() { |
157 StringPiece url(x_original_url_); | 154 StringPiece url(x_original_url_); |
158 // Remove the protocol so we can add it below. | 155 // Remove the protocol so we can add it below. |
159 url = RemoveScheme(url); | 156 url = RemoveScheme(url); |
160 SetHostPathFromBase(url); | 157 SetHostPathFromBase(url); |
(...skipping 16 matching lines...) Expand all Loading... |
177 return it->second.get(); | 174 return it->second.get(); |
178 } | 175 } |
179 | 176 |
180 typedef QuicHttpResponseCache::ServerPushInfo ServerPushInfo; | 177 typedef QuicHttpResponseCache::ServerPushInfo ServerPushInfo; |
181 | 178 |
182 void QuicHttpResponseCache::AddSimpleResponse(StringPiece host, | 179 void QuicHttpResponseCache::AddSimpleResponse(StringPiece host, |
183 StringPiece path, | 180 StringPiece path, |
184 int response_code, | 181 int response_code, |
185 StringPiece body) { | 182 StringPiece body) { |
186 SpdyHeaderBlock response_headers; | 183 SpdyHeaderBlock response_headers; |
187 response_headers[":status"] = IntToString(response_code); | 184 response_headers[":status"] = QuicTextUtils::Uint64ToString(response_code); |
188 response_headers["content-length"] = | 185 response_headers["content-length"] = |
189 IntToString(static_cast<int>(body.length())); | 186 QuicTextUtils::Uint64ToString(body.length()); |
190 AddResponse(host, path, std::move(response_headers), body); | 187 AddResponse(host, path, std::move(response_headers), body); |
191 } | 188 } |
192 | 189 |
193 void QuicHttpResponseCache::AddSimpleResponseWithServerPushResources( | 190 void QuicHttpResponseCache::AddSimpleResponseWithServerPushResources( |
194 StringPiece host, | 191 StringPiece host, |
195 StringPiece path, | 192 StringPiece path, |
196 int response_code, | 193 int response_code, |
197 StringPiece body, | 194 StringPiece body, |
198 std::list<ServerPushInfo> push_resources) { | 195 std::list<ServerPushInfo> push_resources) { |
199 AddSimpleResponse(host, path, response_code, body); | 196 AddSimpleResponse(host, path, response_code, body); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 for (auto it = resource_range.first; it != resource_range.second; ++it) { | 379 for (auto it = resource_range.first; it != resource_range.second; ++it) { |
383 ServerPushInfo push_resource = it->second; | 380 ServerPushInfo push_resource = it->second; |
384 if (push_resource.request_url.spec() == resource.request_url.spec()) { | 381 if (push_resource.request_url.spec() == resource.request_url.spec()) { |
385 return true; | 382 return true; |
386 } | 383 } |
387 } | 384 } |
388 return false; | 385 return false; |
389 } | 386 } |
390 | 387 |
391 } // namespace net | 388 } // namespace net |
OLD | NEW |