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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 const std::string& scheme) { | 251 const std::string& scheme) { |
252 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || | 252 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || |
253 scheme == "wss"); | 253 scheme == "wss"); |
254 | 254 |
255 if (!request->context()->http_transaction_factory()) { | 255 if (!request->context()->http_transaction_factory()) { |
256 NOTREACHED() << "requires a valid context"; | 256 NOTREACHED() << "requires a valid context"; |
257 return new URLRequestErrorJob( | 257 return new URLRequestErrorJob( |
258 request, network_delegate, ERR_INVALID_ARGUMENT); | 258 request, network_delegate, ERR_INVALID_ARGUMENT); |
259 } | 259 } |
260 | 260 |
261 GURL redirect_url; | 261 URLRequestRedirectJob* redirect = |
262 if (request->GetHSTSRedirect(&redirect_url)) { | 262 URLRequestHttpJob::MaybeInternallyRedirect(request, network_delegate); |
263 return new URLRequestRedirectJob( | 263 if (redirect) |
264 request, network_delegate, redirect_url, | 264 return redirect; |
265 // Use status code 307 to preserve the method, so POST requests work. | 265 |
266 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); | |
267 } | |
268 return new URLRequestHttpJob(request, | 266 return new URLRequestHttpJob(request, |
269 network_delegate, | 267 network_delegate, |
270 request->context()->http_user_agent_settings()); | 268 request->context()->http_user_agent_settings()); |
271 } | 269 } |
272 | 270 |
273 URLRequestHttpJob::URLRequestHttpJob( | 271 URLRequestHttpJob::URLRequestHttpJob( |
274 URLRequest* request, | 272 URLRequest* request, |
275 NetworkDelegate* network_delegate, | 273 NetworkDelegate* network_delegate, |
276 const HttpUserAgentSettings* http_user_agent_settings) | 274 const HttpUserAgentSettings* http_user_agent_settings) |
277 : URLRequestJob(request, network_delegate), | 275 : URLRequestJob(request, network_delegate), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 if (sdch_test_activated_) | 320 if (sdch_test_activated_) |
323 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_DECODE); | 321 RecordPacketStats(FilterContext::SDCH_EXPERIMENT_DECODE); |
324 } | 322 } |
325 // Make sure SDCH filters are told to emit histogram data while | 323 // Make sure SDCH filters are told to emit histogram data while |
326 // filter_context_ is still alive. | 324 // filter_context_ is still alive. |
327 DestroyFilters(); | 325 DestroyFilters(); |
328 | 326 |
329 DoneWithRequest(ABORTED); | 327 DoneWithRequest(ABORTED); |
330 } | 328 } |
331 | 329 |
| 330 URLRequestRedirectJob* URLRequestHttpJob::MaybeInternallyRedirect( |
| 331 URLRequest* request, |
| 332 NetworkDelegate* network_delegate) { |
| 333 const GURL& url = request->url(); |
| 334 if (url.SchemeIsCryptographic()) |
| 335 return nullptr; |
| 336 |
| 337 TransportSecurityState* hsts = request->context()->transport_security_state(); |
| 338 if (!hsts || !hsts->ShouldUpgradeToSSL(url.host())) |
| 339 return nullptr; |
| 340 |
| 341 GURL::Replacements replacements; |
| 342 replacements.SetSchemeStr(url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme |
| 343 : url::kWssScheme); |
| 344 return new URLRequestRedirectJob( |
| 345 request, network_delegate, url.ReplaceComponents(replacements), |
| 346 // Use status code 307 to preserve the method, so POST requests work. |
| 347 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); |
| 348 } |
| 349 |
332 void URLRequestHttpJob::SetPriority(RequestPriority priority) { | 350 void URLRequestHttpJob::SetPriority(RequestPriority priority) { |
333 priority_ = priority; | 351 priority_ = priority; |
334 if (transaction_) | 352 if (transaction_) |
335 transaction_->SetPriority(priority_); | 353 transaction_->SetPriority(priority_); |
336 } | 354 } |
337 | 355 |
338 void URLRequestHttpJob::Start() { | 356 void URLRequestHttpJob::Start() { |
339 // TODO(mmenke): Remove ScopedTracker below once crbug.com/456327 is fixed. | 357 // TODO(mmenke): Remove ScopedTracker below once crbug.com/456327 is fixed. |
340 tracked_objects::ScopedTracker tracking_profile( | 358 tracked_objects::ScopedTracker tracking_profile( |
341 FROM_HERE_WITH_EXPLICIT_FUNCTION("456327 URLRequestHttpJob::Start")); | 359 FROM_HERE_WITH_EXPLICIT_FUNCTION("456327 URLRequestHttpJob::Start")); |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 // Notify NetworkQualityEstimator. | 1687 // Notify NetworkQualityEstimator. |
1670 if (request()) { | 1688 if (request()) { |
1671 NetworkQualityEstimator* network_quality_estimator = | 1689 NetworkQualityEstimator* network_quality_estimator = |
1672 request()->context()->network_quality_estimator(); | 1690 request()->context()->network_quality_estimator(); |
1673 if (network_quality_estimator) | 1691 if (network_quality_estimator) |
1674 network_quality_estimator->NotifyURLRequestDestroyed(*request()); | 1692 network_quality_estimator->NotifyURLRequestDestroyed(*request()); |
1675 } | 1693 } |
1676 } | 1694 } |
1677 | 1695 |
1678 } // namespace net | 1696 } // namespace net |
OLD | NEW |