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