| 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 26 matching lines...) Expand all Loading... |
| 37 #include "net/http/http_status_code.h" | 37 #include "net/http/http_status_code.h" |
| 38 #include "net/http/http_transaction.h" | 38 #include "net/http/http_transaction.h" |
| 39 #include "net/http/http_transaction_factory.h" | 39 #include "net/http/http_transaction_factory.h" |
| 40 #include "net/http/http_util.h" | 40 #include "net/http/http_util.h" |
| 41 #include "net/proxy/proxy_info.h" | 41 #include "net/proxy/proxy_info.h" |
| 42 #include "net/ssl/ssl_cert_request_info.h" | 42 #include "net/ssl/ssl_cert_request_info.h" |
| 43 #include "net/ssl/ssl_config_service.h" | 43 #include "net/ssl/ssl_config_service.h" |
| 44 #include "net/url_request/fraudulent_certificate_reporter.h" | 44 #include "net/url_request/fraudulent_certificate_reporter.h" |
| 45 #include "net/url_request/http_user_agent_settings.h" | 45 #include "net/url_request/http_user_agent_settings.h" |
| 46 #include "net/url_request/url_request.h" | 46 #include "net/url_request/url_request.h" |
| 47 #include "net/url_request/url_request_backoff_manager.h" |
| 47 #include "net/url_request/url_request_context.h" | 48 #include "net/url_request/url_request_context.h" |
| 48 #include "net/url_request/url_request_error_job.h" | 49 #include "net/url_request/url_request_error_job.h" |
| 49 #include "net/url_request/url_request_job_factory.h" | 50 #include "net/url_request/url_request_job_factory.h" |
| 50 #include "net/url_request/url_request_redirect_job.h" | 51 #include "net/url_request/url_request_redirect_job.h" |
| 51 #include "net/url_request/url_request_throttler_manager.h" | 52 #include "net/url_request/url_request_throttler_manager.h" |
| 52 #include "net/websockets/websocket_handshake_stream_base.h" | 53 #include "net/websockets/websocket_handshake_stream_base.h" |
| 53 | 54 |
| 54 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; | 55 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
| 55 | 56 |
| 56 namespace net { | 57 namespace net { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 done_(false), | 189 done_(false), |
| 189 bytes_observed_in_packets_(0), | 190 bytes_observed_in_packets_(0), |
| 190 request_time_snapshot_(), | 191 request_time_snapshot_(), |
| 191 final_packet_time_(), | 192 final_packet_time_(), |
| 192 filter_context_(new HttpFilterContext(this)), | 193 filter_context_(new HttpFilterContext(this)), |
| 193 on_headers_received_callback_( | 194 on_headers_received_callback_( |
| 194 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, | 195 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, |
| 195 base::Unretained(this))), | 196 base::Unretained(this))), |
| 196 awaiting_callback_(false), | 197 awaiting_callback_(false), |
| 197 http_user_agent_settings_(http_user_agent_settings), | 198 http_user_agent_settings_(http_user_agent_settings), |
| 199 backoff_manager_(request->context()->backoff_manager()), |
| 198 weak_factory_(this) { | 200 weak_factory_(this) { |
| 199 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); | 201 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 200 if (manager) | 202 if (manager) |
| 201 throttling_entry_ = manager->RegisterRequestUrl(request->url()); | 203 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 202 | 204 |
| 203 ResetTimer(); | 205 ResetTimer(); |
| 204 } | 206 } |
| 205 | 207 |
| 206 URLRequestHttpJob::~URLRequestHttpJob() { | 208 URLRequestHttpJob::~URLRequestHttpJob() { |
| 207 CHECK(!awaiting_callback_); | 209 CHECK(!awaiting_callback_); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 DCHECK(request_headers); | 296 DCHECK(request_headers); |
| 295 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); | 297 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 296 if (network_delegate()) { | 298 if (network_delegate()) { |
| 297 network_delegate()->NotifyBeforeSendProxyHeaders( | 299 network_delegate()->NotifyBeforeSendProxyHeaders( |
| 298 request_, | 300 request_, |
| 299 proxy_info, | 301 proxy_info, |
| 300 request_headers); | 302 request_headers); |
| 301 } | 303 } |
| 302 } | 304 } |
| 303 | 305 |
| 306 void URLRequestHttpJob::NotifyBeforeNetworkStart(bool* defer) { |
| 307 if (!request_) |
| 308 return; |
| 309 if (backoff_manager_) { |
| 310 if (backoff_manager_->ShouldRejectRequest(request()->url(), |
| 311 request()->request_time())) { |
| 312 *defer = true; |
| 313 base::MessageLoop::current()->PostTask( |
| 314 FROM_HERE, |
| 315 base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 316 weak_factory_.GetWeakPtr(), ERR_TEMPORARY_BACKOFF)); |
| 317 return; |
| 318 } |
| 319 } |
| 320 URLRequestJob::NotifyBeforeNetworkStart(defer); |
| 321 } |
| 322 |
| 304 void URLRequestHttpJob::NotifyHeadersComplete() { | 323 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 305 DCHECK(!response_info_); | 324 DCHECK(!response_info_); |
| 306 | 325 |
| 307 response_info_ = transaction_->GetResponseInfo(); | 326 response_info_ = transaction_->GetResponseInfo(); |
| 308 | 327 |
| 309 // Save boolean, as we'll need this info at destruction time, and filters may | 328 // Save boolean, as we'll need this info at destruction time, and filters may |
| 310 // also need this info. | 329 // also need this info. |
| 311 is_cached_content_ = response_info_->was_cached; | 330 is_cached_content_ = response_info_->was_cached; |
| 312 | 331 |
| 313 if (!is_cached_content_ && throttling_entry_.get()) | 332 if (!is_cached_content_ && throttling_entry_.get()) |
| 314 throttling_entry_->UpdateWithResponse(GetResponseCode()); | 333 throttling_entry_->UpdateWithResponse(GetResponseCode()); |
| 315 | 334 |
| 335 if (!is_cached_content_) |
| 336 ProcessBackoffHeader(); |
| 337 |
| 316 // The ordering of these calls is not important. | 338 // The ordering of these calls is not important. |
| 317 ProcessStrictTransportSecurityHeader(); | 339 ProcessStrictTransportSecurityHeader(); |
| 318 ProcessPublicKeyPinsHeader(); | 340 ProcessPublicKeyPinsHeader(); |
| 319 | 341 |
| 320 // Handle the server notification of a new SDCH dictionary. | 342 // Handle the server notification of a new SDCH dictionary. |
| 321 SdchManager* sdch_manager(request()->context()->sdch_manager()); | 343 SdchManager* sdch_manager(request()->context()->sdch_manager()); |
| 322 if (sdch_manager) { | 344 if (sdch_manager) { |
| 323 SdchProblemCode rv = sdch_manager->IsInSupportedDomain(request()->url()); | 345 SdchProblemCode rv = sdch_manager->IsInSupportedDomain(request()->url()); |
| 324 if (rv != SDCH_OK) { | 346 if (rv != SDCH_OK) { |
| 325 // If SDCH is just disabled, it is not a real error. | 347 // If SDCH is just disabled, it is not a real error. |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 std::string value; | 811 std::string value; |
| 790 | 812 |
| 791 void* iter = NULL; | 813 void* iter = NULL; |
| 792 HttpResponseHeaders* headers = GetResponseHeaders(); | 814 HttpResponseHeaders* headers = GetResponseHeaders(); |
| 793 while (headers->EnumerateHeader(&iter, name, &value)) { | 815 while (headers->EnumerateHeader(&iter, name, &value)) { |
| 794 if (!value.empty()) | 816 if (!value.empty()) |
| 795 cookies->push_back(value); | 817 cookies->push_back(value); |
| 796 } | 818 } |
| 797 } | 819 } |
| 798 | 820 |
| 821 void URLRequestHttpJob::ProcessBackoffHeader() { |
| 822 DCHECK(response_info_); |
| 823 |
| 824 if (!backoff_manager_) |
| 825 return; |
| 826 |
| 827 TransportSecurityState* security_state = |
| 828 request_->context()->transport_security_state(); |
| 829 const SSLInfo& ssl_info = response_info_->ssl_info; |
| 830 |
| 831 // Only accept Backoff headers on HTTPS connections that have no |
| 832 // certificate errors. |
| 833 if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
| 834 !security_state) |
| 835 return; |
| 836 |
| 837 backoff_manager_->UpdateWithResponse(request()->url(), GetResponseHeaders(), |
| 838 base::Time::Now()); |
| 839 } |
| 840 |
| 799 // NOTE: |ProcessStrictTransportSecurityHeader| and | 841 // NOTE: |ProcessStrictTransportSecurityHeader| and |
| 800 // |ProcessPublicKeyPinsHeader| have very similar structures, by design. | 842 // |ProcessPublicKeyPinsHeader| have very similar structures, by design. |
| 801 void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { | 843 void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { |
| 802 DCHECK(response_info_); | 844 DCHECK(response_info_); |
| 803 TransportSecurityState* security_state = | 845 TransportSecurityState* security_state = |
| 804 request_->context()->transport_security_state(); | 846 request_->context()->transport_security_state(); |
| 805 const SSLInfo& ssl_info = response_info_->ssl_info; | 847 const SSLInfo& ssl_info = response_info_->ssl_info; |
| 806 | 848 |
| 807 // Only accept HSTS headers on HTTPS connections that have no | 849 // Only accept HSTS headers on HTTPS connections that have no |
| 808 // certificate errors. | 850 // certificate errors. |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 return override_response_headers_.get() ? | 1552 return override_response_headers_.get() ? |
| 1511 override_response_headers_.get() : | 1553 override_response_headers_.get() : |
| 1512 transaction_->GetResponseInfo()->headers.get(); | 1554 transaction_->GetResponseInfo()->headers.get(); |
| 1513 } | 1555 } |
| 1514 | 1556 |
| 1515 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1557 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1516 awaiting_callback_ = false; | 1558 awaiting_callback_ = false; |
| 1517 } | 1559 } |
| 1518 | 1560 |
| 1519 } // namespace net | 1561 } // namespace net |
| OLD | NEW |