| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "net/base/cert_status_flags.h" | 15 #include "net/base/cert_status_flags.h" |
| 16 #include "net/base/cookie_policy.h" | 16 #include "net/base/cookie_policy.h" |
| 17 #include "net/base/filter.h" | 17 #include "net/base/filter.h" |
| 18 #include "net/base/transport_security_state.h" | 18 #include "net/base/transport_security_state.h" |
| 19 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 22 #include "net/base/sdch_manager.h" | 22 #include "net/base/sdch_manager.h" |
| 23 #include "net/base/ssl_cert_request_info.h" | 23 #include "net/base/ssl_cert_request_info.h" |
| 24 #include "net/http/http_request_headers.h" | 24 #include "net/http/http_request_headers.h" |
| 25 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 26 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
| 27 #include "net/http/http_transaction.h" | 27 #include "net/http/http_transaction.h" |
| 28 #include "net/http/http_transaction_factory.h" | 28 #include "net/http/http_transaction_factory.h" |
| 29 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
| 30 #include "net/request_throttler/request_throttler_header_adapter.h" |
| 30 #include "net/url_request/https_prober.h" | 31 #include "net/url_request/https_prober.h" |
| 31 #include "net/url_request/url_request.h" | 32 #include "net/url_request/url_request.h" |
| 32 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
| 33 #include "net/url_request/url_request_error_job.h" | 34 #include "net/url_request/url_request_error_job.h" |
| 34 #include "net/url_request/url_request_redirect_job.h" | 35 #include "net/url_request/url_request_redirect_job.h" |
| 35 | 36 |
| 36 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; | 37 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
| 37 | 38 |
| 38 // TODO(darin): make sure the port blocking code is not lost | 39 // TODO(darin): make sure the port blocking code is not lost |
| 39 // static | 40 // static |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( | 85 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( |
| 85 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), | 86 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), |
| 86 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( | 87 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( |
| 87 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), | 88 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), |
| 88 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 89 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
| 89 this, &URLRequestHttpJob::OnStartCompleted)), | 90 this, &URLRequestHttpJob::OnStartCompleted)), |
| 90 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | 91 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( |
| 91 this, &URLRequestHttpJob::OnReadCompleted)), | 92 this, &URLRequestHttpJob::OnReadCompleted)), |
| 92 read_in_progress_(false), | 93 read_in_progress_(false), |
| 93 transaction_(NULL), | 94 transaction_(NULL), |
| 95 throttling_entry_(Singleton<RequestThrottlerManager>::get()-> |
| 96 RegisterRequestUrl(request->url())), |
| 94 sdch_dictionary_advertised_(false), | 97 sdch_dictionary_advertised_(false), |
| 95 sdch_test_activated_(false), | 98 sdch_test_activated_(false), |
| 96 sdch_test_control_(false), | 99 sdch_test_control_(false), |
| 97 is_cached_content_(false) { | 100 is_cached_content_(false) { |
| 98 } | 101 } |
| 99 | 102 |
| 100 URLRequestHttpJob::~URLRequestHttpJob() { | 103 URLRequestHttpJob::~URLRequestHttpJob() { |
| 101 DCHECK(!sdch_test_control_ || !sdch_test_activated_); | 104 DCHECK(!sdch_test_control_ || !sdch_test_activated_); |
| 102 if (!IsCachedContent()) { | 105 if (!IsCachedContent()) { |
| 103 if (sdch_test_control_) | 106 if (sdch_test_control_) |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 | 565 |
| 563 void URLRequestHttpJob::NotifyHeadersComplete() { | 566 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 564 DCHECK(!response_info_); | 567 DCHECK(!response_info_); |
| 565 | 568 |
| 566 response_info_ = transaction_->GetResponseInfo(); | 569 response_info_ = transaction_->GetResponseInfo(); |
| 567 | 570 |
| 568 // Save boolean, as we'll need this info at destruction time, and filters may | 571 // Save boolean, as we'll need this info at destruction time, and filters may |
| 569 // also need this info. | 572 // also need this info. |
| 570 is_cached_content_ = response_info_->was_cached; | 573 is_cached_content_ = response_info_->was_cached; |
| 571 | 574 |
| 575 if (!is_cached_content_) { |
| 576 RequestThrottlerHeaderAdapter response_adapter(response_info_->headers); |
| 577 throttling_entry_->UpdateWithResponse(&response_adapter); |
| 578 } |
| 579 |
| 572 ProcessStrictTransportSecurityHeader(); | 580 ProcessStrictTransportSecurityHeader(); |
| 573 | 581 |
| 574 if (SdchManager::Global() && | 582 if (SdchManager::Global() && |
| 575 SdchManager::Global()->IsInSupportedDomain(request_->url())) { | 583 SdchManager::Global()->IsInSupportedDomain(request_->url())) { |
| 576 static const std::string name = "Get-Dictionary"; | 584 static const std::string name = "Get-Dictionary"; |
| 577 std::string url_text; | 585 std::string url_text; |
| 578 void* iter = NULL; | 586 void* iter = NULL; |
| 579 // TODO(jar): We need to not fetch dictionaries the first time they are | 587 // TODO(jar): We need to not fetch dictionaries the first time they are |
| 580 // seen, but rather wait until we can justify their usefulness. | 588 // seen, but rather wait until we can justify their usefulness. |
| 581 // For now, we will only fetch the first dictionary, which will at least | 589 // For now, we will only fetch the first dictionary, which will at least |
| (...skipping 27 matching lines...) Expand all Loading... |
| 609 transaction_.reset(); | 617 transaction_.reset(); |
| 610 response_info_ = NULL; | 618 response_info_ = NULL; |
| 611 } | 619 } |
| 612 | 620 |
| 613 void URLRequestHttpJob::StartTransaction() { | 621 void URLRequestHttpJob::StartTransaction() { |
| 614 // NOTE: This method assumes that request_info_ is already setup properly. | 622 // NOTE: This method assumes that request_info_ is already setup properly. |
| 615 | 623 |
| 616 // If we already have a transaction, then we should restart the transaction | 624 // If we already have a transaction, then we should restart the transaction |
| 617 // with auth provided by username_ and password_. | 625 // with auth provided by username_ and password_. |
| 618 | 626 |
| 619 int rv; | 627 int return_value; |
| 628 |
| 620 if (transaction_.get()) { | 629 if (transaction_.get()) { |
| 621 rv = transaction_->RestartWithAuth(username_, password_, &start_callback_); | 630 return_value = transaction_->RestartWithAuth(username_, |
| 631 password_, &start_callback_); |
| 622 username_.clear(); | 632 username_.clear(); |
| 623 password_.clear(); | 633 password_.clear(); |
| 624 } else { | 634 } else { |
| 625 DCHECK(request_->context()); | 635 DCHECK(request_->context()); |
| 626 DCHECK(request_->context()->http_transaction_factory()); | 636 DCHECK(request_->context()->http_transaction_factory()); |
| 627 | 637 |
| 628 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 638 return_value = request_->context()->http_transaction_factory()-> |
| 629 &transaction_); | 639 CreateTransaction(&transaction_); |
| 630 if (rv == net::OK) { | 640 if (return_value == net::OK) { |
| 631 rv = transaction_->Start( | 641 if (throttling_entry_->IsRequestAllowed()) { |
| 632 &request_info_, &start_callback_, request_->net_log()); | 642 return_value = transaction_->Start( |
| 643 &request_info_, &start_callback_, request_->net_log()); |
| 644 } else { |
| 645 // Special error code for the exponential back-off module. |
| 646 return_value = net::ERR_TEMPORARILY_THROTTLED_BY_DDOS; |
| 647 } |
| 633 } | 648 } |
| 634 } | 649 } |
| 635 | 650 |
| 636 if (rv == net::ERR_IO_PENDING) | 651 if (return_value == net::ERR_IO_PENDING) |
| 637 return; | 652 return; |
| 638 | 653 |
| 639 // The transaction started synchronously, but we need to notify the | 654 // The transaction started synchronously, but we need to notify the |
| 640 // URLRequest delegate via the message loop. | 655 // URLRequest delegate via the message loop. |
| 641 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 656 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 642 this, &URLRequestHttpJob::OnStartCompleted, rv)); | 657 this, &URLRequestHttpJob::OnStartCompleted, return_value)); |
| 643 } | 658 } |
| 644 | 659 |
| 645 void URLRequestHttpJob::AddExtraHeaders() { | 660 void URLRequestHttpJob::AddExtraHeaders() { |
| 646 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is | 661 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is |
| 647 // probably an img or such (and SDCH encoding is not likely). | 662 // probably an img or such (and SDCH encoding is not likely). |
| 648 bool advertise_sdch = SdchManager::Global() && | 663 bool advertise_sdch = SdchManager::Global() && |
| 649 SdchManager::Global()->IsInSupportedDomain(request_->url()); | 664 SdchManager::Global()->IsInSupportedDomain(request_->url()); |
| 650 std::string avail_dictionaries; | 665 std::string avail_dictionaries; |
| 651 if (advertise_sdch) { | 666 if (advertise_sdch) { |
| 652 SdchManager::Global()->GetAvailDictionaryList(request_->url(), | 667 SdchManager::Global()->GetAvailDictionaryList(request_->url(), |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 HTTPSProberDelegate* delegate = | 925 HTTPSProberDelegate* delegate = |
| 911 new HTTPSProberDelegate(request_info_.url.host(), max_age, | 926 new HTTPSProberDelegate(request_info_.url.host(), max_age, |
| 912 include_subdomains, | 927 include_subdomains, |
| 913 ctx->transport_security_state()); | 928 ctx->transport_security_state()); |
| 914 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), | 929 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), |
| 915 delegate)) { | 930 delegate)) { |
| 916 delete delegate; | 931 delete delegate; |
| 917 } | 932 } |
| 918 } | 933 } |
| 919 } | 934 } |
| OLD | NEW |