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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 params->channel_id_service->GetUniqueID()) { | 151 params->channel_id_service->GetUniqueID()) { |
152 ephemerality = PERSISTENT_MATCH; | 152 ephemerality = PERSISTENT_MATCH; |
153 } else { | 153 } else { |
154 NOTREACHED(); | 154 NOTREACHED(); |
155 ephemerality = PERSISTENT_MISMATCH; | 155 ephemerality = PERSISTENT_MISMATCH; |
156 } | 156 } |
157 UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.StoreEphemerality", ephemerality, | 157 UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.StoreEphemerality", ephemerality, |
158 EPHEMERALITY_MAX); | 158 EPHEMERALITY_MAX); |
159 } | 159 } |
160 | 160 |
| 161 net::URLRequestRedirectJob* MaybeInternallyRedirect( |
| 162 net::URLRequest* request, |
| 163 net::NetworkDelegate* network_delegate) { |
| 164 const GURL& url = request->url(); |
| 165 if (url.SchemeIsCryptographic()) |
| 166 return nullptr; |
| 167 |
| 168 net::TransportSecurityState* hsts = |
| 169 request->context()->transport_security_state(); |
| 170 if (!hsts || !hsts->ShouldUpgradeToSSL(url.host())) |
| 171 return nullptr; |
| 172 |
| 173 GURL::Replacements replacements; |
| 174 replacements.SetSchemeStr(url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme |
| 175 : url::kWssScheme); |
| 176 return new net::URLRequestRedirectJob( |
| 177 request, network_delegate, url.ReplaceComponents(replacements), |
| 178 // Use status code 307 to preserve the method, so POST requests work. |
| 179 net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); |
| 180 } |
| 181 |
161 } // namespace | 182 } // namespace |
162 | 183 |
163 namespace net { | 184 namespace net { |
164 | 185 |
165 class URLRequestHttpJob::HttpFilterContext : public FilterContext { | 186 class URLRequestHttpJob::HttpFilterContext : public FilterContext { |
166 public: | 187 public: |
167 explicit HttpFilterContext(URLRequestHttpJob* job); | 188 explicit HttpFilterContext(URLRequestHttpJob* job); |
168 ~HttpFilterContext() override; | 189 ~HttpFilterContext() override; |
169 | 190 |
170 // FilterContext implementation. | 191 // FilterContext implementation. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 const std::string& scheme) { | 272 const std::string& scheme) { |
252 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || | 273 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || |
253 scheme == "wss"); | 274 scheme == "wss"); |
254 | 275 |
255 if (!request->context()->http_transaction_factory()) { | 276 if (!request->context()->http_transaction_factory()) { |
256 NOTREACHED() << "requires a valid context"; | 277 NOTREACHED() << "requires a valid context"; |
257 return new URLRequestErrorJob( | 278 return new URLRequestErrorJob( |
258 request, network_delegate, ERR_INVALID_ARGUMENT); | 279 request, network_delegate, ERR_INVALID_ARGUMENT); |
259 } | 280 } |
260 | 281 |
261 GURL redirect_url; | 282 URLRequestRedirectJob* redirect = |
262 if (request->GetHSTSRedirect(&redirect_url)) { | 283 MaybeInternallyRedirect(request, network_delegate); |
263 return new URLRequestRedirectJob( | 284 if (redirect) |
264 request, network_delegate, redirect_url, | 285 return redirect; |
265 // Use status code 307 to preserve the method, so POST requests work. | 286 |
266 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); | |
267 } | |
268 return new URLRequestHttpJob(request, | 287 return new URLRequestHttpJob(request, |
269 network_delegate, | 288 network_delegate, |
270 request->context()->http_user_agent_settings()); | 289 request->context()->http_user_agent_settings()); |
271 } | 290 } |
272 | 291 |
273 URLRequestHttpJob::URLRequestHttpJob( | 292 URLRequestHttpJob::URLRequestHttpJob( |
274 URLRequest* request, | 293 URLRequest* request, |
275 NetworkDelegate* network_delegate, | 294 NetworkDelegate* network_delegate, |
276 const HttpUserAgentSettings* http_user_agent_settings) | 295 const HttpUserAgentSettings* http_user_agent_settings) |
277 : URLRequestJob(request, network_delegate), | 296 : URLRequestJob(request, network_delegate), |
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 // Notify NetworkQualityEstimator. | 1688 // Notify NetworkQualityEstimator. |
1670 if (request()) { | 1689 if (request()) { |
1671 NetworkQualityEstimator* network_quality_estimator = | 1690 NetworkQualityEstimator* network_quality_estimator = |
1672 request()->context()->network_quality_estimator(); | 1691 request()->context()->network_quality_estimator(); |
1673 if (network_quality_estimator) | 1692 if (network_quality_estimator) |
1674 network_quality_estimator->NotifyURLRequestDestroyed(*request()); | 1693 network_quality_estimator->NotifyURLRequestDestroyed(*request()); |
1675 } | 1694 } |
1676 } | 1695 } |
1677 | 1696 |
1678 } // namespace net | 1697 } // namespace net |
OLD | NEW |