Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 16 #include "base/string_number_conversions.h" | |
| 16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "net/base/cert_status_flags.h" | 19 #include "net/base/cert_status_flags.h" |
| 19 #include "net/base/cookie_store.h" | 20 #include "net/base/cookie_store.h" |
| 20 #include "net/base/filter.h" | 21 #include "net/base/filter.h" |
| 21 #include "net/base/host_port_pair.h" | 22 #include "net/base/host_port_pair.h" |
| 22 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 23 #include "net/base/mime_util.h" | 24 #include "net/base/mime_util.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 26 #include "net/base/sdch_manager.h" | 27 #include "net/base/sdch_manager.h" |
| 27 #include "net/base/ssl_cert_request_info.h" | 28 #include "net/base/ssl_cert_request_info.h" |
| 28 #include "net/base/ssl_config_service.h" | 29 #include "net/base/ssl_config_service.h" |
| 29 #include "net/base/transport_security_state.h" | 30 #include "net/base/transport_security_state.h" |
| 31 #include "net/http/http_mac_signature.h" | |
| 30 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
| 31 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_response_info.h" | 34 #include "net/http/http_response_info.h" |
| 33 #include "net/http/http_transaction.h" | 35 #include "net/http/http_transaction.h" |
| 34 #include "net/http/http_transaction_factory.h" | 36 #include "net/http/http_transaction_factory.h" |
| 35 #include "net/http/http_util.h" | 37 #include "net/http/http_util.h" |
| 36 #include "net/url_request/https_prober.h" | 38 #include "net/url_request/https_prober.h" |
| 37 #include "net/url_request/url_request.h" | 39 #include "net/url_request/url_request.h" |
| 38 #include "net/url_request/url_request_context.h" | 40 #include "net/url_request/url_request_context.h" |
| 39 #include "net/url_request/url_request_error_job.h" | 41 #include "net/url_request/url_request_error_job.h" |
| 40 #include "net/url_request/url_request_redirect_job.h" | 42 #include "net/url_request/url_request_redirect_job.h" |
| 41 #include "net/url_request/url_request_throttler_header_adapter.h" | 43 #include "net/url_request/url_request_throttler_header_adapter.h" |
| 42 #include "net/url_request/url_request_throttler_manager.h" | 44 #include "net/url_request/url_request_throttler_manager.h" |
| 43 | 45 |
| 44 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; | 46 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
| 45 | 47 |
| 46 // When histogramming results related to SDCH and/or an SDCH latency test, the | 48 // When histogramming results related to SDCH and/or an SDCH latency test, the |
| 47 // number of packets for which we need to record arrival times so as to | 49 // number of packets for which we need to record arrival times so as to |
| 48 // calculate interpacket latencies. We currently are only looking at the | 50 // calculate interpacket latencies. We currently are only looking at the |
| 49 // first few packets, as we're monitoring the impact of the initial TCP | 51 // first few packets, as we're monitoring the impact of the initial TCP |
| 50 // congestion window on stalling of transmissions. | 52 // congestion window on stalling of transmissions. |
| 51 static const size_t kSdchPacketHistogramCount = 5; | 53 static const size_t kSdchPacketHistogramCount = 5; |
| 52 | 54 |
| 53 namespace net { | 55 namespace net { |
| 54 | 56 |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 59 std::string BuildIssuerForMac(const std::string& source) { | |
| 60 // TODO(abarth): The issuer has had its scheme doctored! | |
| 61 GURL issuer(source); | |
| 62 // Notice that we include the port even if the port is the default port. | |
| 63 // TODO(abarth): We're geting the wrong port number here. | |
| 64 return issuer.host() + ":" + base::IntToString(issuer.IntPort()); | |
|
cbentzel
2011/05/13 14:05:45
You can just use GetHostAndPort from net_util.h he
| |
| 65 } | |
| 66 | |
| 57 class HTTPSProberDelegateImpl : public HTTPSProberDelegate { | 67 class HTTPSProberDelegateImpl : public HTTPSProberDelegate { |
| 58 public: | 68 public: |
| 59 HTTPSProberDelegateImpl(const std::string& host, int max_age, | 69 HTTPSProberDelegateImpl(const std::string& host, int max_age, |
| 60 bool include_subdomains, | 70 bool include_subdomains, |
| 61 TransportSecurityState* sts) | 71 TransportSecurityState* sts) |
| 62 : host_(host), | 72 : host_(host), |
| 63 max_age_(max_age), | 73 max_age_(max_age), |
| 64 include_subdomains_(include_subdomains), | 74 include_subdomains_(include_subdomains), |
| 65 sts_(sts) { } | 75 sts_(sts) { } |
| 66 | 76 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 new HTTPSProberDelegateImpl(request_info_.url.host(), max_age, | 591 new HTTPSProberDelegateImpl(request_info_.url.host(), max_age, |
| 582 include_subdomains, | 592 include_subdomains, |
| 583 ctx->transport_security_state()); | 593 ctx->transport_security_state()); |
| 584 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), | 594 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), |
| 585 delegate)) { | 595 delegate)) { |
| 586 delete delegate; | 596 delete delegate; |
| 587 } | 597 } |
| 588 } | 598 } |
| 589 } | 599 } |
| 590 | 600 |
| 601 void URLRequestHttpJob::AddAuthorizationHeader( | |
|
cbentzel
2011/05/13 14:05:45
You could make a static/top-level function which p
abarth-chromium
2011/05/13 17:36:23
Yeah, that makes unit testing at this layer slight
| |
| 602 const std::vector<CookieStore::CookieInfo>& cookie_infos) { | |
| 603 const GURL& url = request_info_.url; | |
| 604 const std::string& method = request_info_.method; | |
| 605 std::string request_uri = HttpUtil::PathForRequest(url); | |
| 606 const std::string& host = url.host(); | |
| 607 int port = url.IntPort(); | |
|
cbentzel
2011/05/13 14:05:45
You'll want to use EffectiveIntPort here to captur
abarth-chromium
2011/05/13 17:36:23
Done.
| |
| 608 | |
| 609 for (size_t i = 0; i < cookie_infos.size(); ++i) { | |
| 610 const CookieStore::CookieInfo& cookie_info = cookie_infos[i]; | |
| 611 if (cookie_info.mac_key.empty() || cookie_info.mac_algorithm.empty()) | |
|
cbentzel
2011/05/13 14:05:45
I would remove the empty string tests here, since
abarth-chromium
2011/05/13 17:36:23
Done.
| |
| 612 continue; | |
| 613 HttpMacSignature signature; | |
| 614 if (!signature.AddStateInfo(cookie_info.name, | |
| 615 cookie_info.mac_key, | |
| 616 cookie_info.mac_algorithm, | |
| 617 BuildIssuerForMac(cookie_info.source))) { | |
| 618 continue; | |
| 619 } | |
| 620 if (!signature.AddHttpInfo(method, request_uri, host, port)) | |
| 621 continue; | |
| 622 request_info_.extra_headers.SetHeader( | |
| 623 HttpRequestHeaders::kAuthorization, | |
| 624 signature.GenerateAuthorizationHeader()); | |
| 625 return; // Only add the first valid header. | |
|
cbentzel
2011/05/13 14:05:45
I thought you were planning to support multiple Au
| |
| 626 } | |
| 627 } | |
| 628 | |
| 591 void URLRequestHttpJob::OnCanGetCookiesCompleted(bool allow) { | 629 void URLRequestHttpJob::OnCanGetCookiesCompleted(bool allow) { |
| 592 if (request_->context()->cookie_store() && allow) { | 630 if (request_->context()->cookie_store() && allow) { |
| 593 CookieOptions options; | 631 CookieOptions options; |
| 594 options.set_include_httponly(); | 632 options.set_include_httponly(); |
| 595 std::string cookies = | 633 std::string cookie_line; |
| 596 request_->context()->cookie_store()->GetCookiesWithOptions( | 634 std::vector<CookieStore::CookieInfo> cookie_infos; |
| 597 request_->url(), options); | 635 request_->context()->cookie_store()->GetCookiesWithInfo( |
| 598 if (!cookies.empty()) { | 636 request_->url(), options, &cookie_line, &cookie_infos); |
| 637 if (!cookie_line.empty()) { | |
| 599 request_info_.extra_headers.SetHeader( | 638 request_info_.extra_headers.SetHeader( |
| 600 HttpRequestHeaders::kCookie, cookies); | 639 HttpRequestHeaders::kCookie, cookie_line); |
| 601 } | 640 } |
| 641 | |
| 642 if (URLRequest::AreMacCookiesEnabled()) | |
| 643 AddAuthorizationHeader(cookie_infos); | |
| 602 } | 644 } |
| 603 // We may have been canceled within CanGetCookies. | 645 // We may have been canceled within CanGetCookies. |
| 604 if (GetStatus().is_success()) { | 646 if (GetStatus().is_success()) { |
| 605 StartTransaction(); | 647 StartTransaction(); |
| 606 } else { | 648 } else { |
| 607 NotifyCanceled(); | 649 NotifyCanceled(); |
| 608 } | 650 } |
| 609 } | 651 } |
| 610 | 652 |
| 611 void URLRequestHttpJob::OnCanSetCookieCompleted() { | 653 void URLRequestHttpJob::OnCanSetCookieCompleted() { |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1367 } | 1409 } |
| 1368 | 1410 |
| 1369 bool URLRequestHttpJob::IsCompressibleContent() const { | 1411 bool URLRequestHttpJob::IsCompressibleContent() const { |
| 1370 std::string mime_type; | 1412 std::string mime_type; |
| 1371 return GetMimeType(&mime_type) && | 1413 return GetMimeType(&mime_type) && |
| 1372 (IsSupportedJavascriptMimeType(mime_type.c_str()) || | 1414 (IsSupportedJavascriptMimeType(mime_type.c_str()) || |
| 1373 IsSupportedNonImageMimeType(mime_type.c_str())); | 1415 IsSupportedNonImageMimeType(mime_type.c_str())); |
| 1374 } | 1416 } |
| 1375 | 1417 |
| 1376 } // namespace net | 1418 } // namespace net |
| OLD | NEW |