[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 5 | #include "net/url_request/url_request_http_job.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 6 | |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | 4ed2755f | 2008-12-15 09:01:33 | [diff] [blame] | 9 | #include "base/base_switches.h" |
[email protected] | 4f9e5c8 | 2011-11-17 16:04:56 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 11 | #include "base/bind_helpers.h" |
[email protected] | 4ed2755f | 2008-12-15 09:01:33 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 39ce5c0 | 2008-08-22 04:03:44 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 6088942 | 2008-09-23 01:18:16 | [diff] [blame] | 14 | #include "base/file_version_info.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 15 | #include "base/location.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 8684a881 | 2011-03-22 13:59:38 | [diff] [blame] | 17 | #include "base/metrics/field_trial.h" |
Devdeep Ray | 0c6966d | 2017-07-14 00:58:22 | [diff] [blame] | 18 | #include "base/metrics/histogram_functions.h" |
asvitkine | c3c9372 | 2015-06-17 14:48:37 | [diff] [blame] | 19 | #include "base/metrics/histogram_macros.h" |
[email protected] | 5b90b5d | 2009-04-30 23:06:01 | [diff] [blame] | 20 | #include "base/rand_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 21 | #include "base/single_thread_task_runner.h" |
[email protected] | 4dc3ad4f | 2013-06-11 07:15:50 | [diff] [blame] | 22 | #include "base/strings/string_util.h" |
Devdeep Ray | 0c6966d | 2017-07-14 00:58:22 | [diff] [blame] | 23 | #include "base/strings/stringprintf.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 24 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | f002abb | 2013-06-28 02:30:21 | [diff] [blame] | 25 | #include "base/time/time.h" |
ssid | 6d6b4010 | 2016-04-05 18:59:56 | [diff] [blame] | 26 | #include "base/trace_event/trace_event.h" |
estade | 5e5529d | 2015-05-21 20:59:11 | [diff] [blame] | 27 | #include "base/values.h" |
mmenke | fd9d15c | 2017-06-29 13:45:54 | [diff] [blame] | 28 | #include "build/buildflag.h" |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 29 | #include "net/base/host_port_pair.h" |
[email protected] | b843072 | 2008-09-17 20:05:44 | [diff] [blame] | 30 | #include "net/base/load_flags.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 31 | #include "net/base/net_errors.h" |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 32 | #include "net/base/network_delegate.h" |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 33 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
xunjieli | 0b7f5b6 | 2016-12-06 20:43:48 | [diff] [blame] | 34 | #include "net/base/trace_constants.h" |
tfarina | 7a4a7fd | 2016-01-20 14:23:44 | [diff] [blame] | 35 | #include "net/base/url_util.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 36 | #include "net/cert/cert_status_flags.h" |
Emily Stark | 8b411de0 | 2017-11-23 20:21:27 | [diff] [blame] | 37 | #include "net/cert/ct_policy_status.h" |
Ryan Sleevi | 19a7bde | 2017-11-22 06:51:39 | [diff] [blame] | 38 | #include "net/cert/known_roots.h" |
Randy Smith | e23356c2 | 2017-11-14 01:41:50 | [diff] [blame] | 39 | #include "net/cookies/canonical_cookie.h" |
[email protected] | dc8313a | 2014-03-24 21:38:14 | [diff] [blame] | 40 | #include "net/cookies/cookie_store.h" |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 41 | #include "net/filter/brotli_source_stream.h" |
| 42 | #include "net/filter/filter_source_stream.h" |
| 43 | #include "net/filter/gzip_source_stream.h" |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 44 | #include "net/filter/source_stream.h" |
[email protected] | 26219171 | 2014-03-22 00:46:57 | [diff] [blame] | 45 | #include "net/http/http_content_disposition.h" |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 46 | #include "net/http/http_network_session.h" |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 47 | #include "net/http/http_request_headers.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 48 | #include "net/http/http_response_headers.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/http/http_response_info.h" |
[email protected] | 9094b60 | 2012-02-27 21:44:58 | [diff] [blame] | 50 | #include "net/http/http_status_code.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 51 | #include "net/http/http_transaction.h" |
| 52 | #include "net/http/http_transaction_factory.h" |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 53 | #include "net/http/http_util.h" |
Ryan Hamilton | 0bed157 | 2018-03-02 19:58:21 | [diff] [blame] | 54 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 55 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 56 | #include "net/log/net_log_with_source.h" |
Scott Violet | 0caaaf43 | 2018-03-24 00:43:59 | [diff] [blame] | 57 | #include "net/net_buildflags.h" |
tbansal | ca83c00 | 2016-04-28 20:56:28 | [diff] [blame] | 58 | #include "net/nqe/network_quality_estimator.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 59 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 60 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 61 | #include "net/proxy_resolution/proxy_retry_info.h" |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 62 | #include "net/ssl/channel_id_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 63 | #include "net/ssl/ssl_cert_request_info.h" |
| 64 | #include "net/ssl/ssl_config_service.h" |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 65 | #include "net/url_request/http_user_agent_settings.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 66 | #include "net/url_request/url_request.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 67 | #include "net/url_request/url_request_context.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 68 | #include "net/url_request/url_request_error_job.h" |
Thiemo Nagel | 0793b9c53 | 2018-04-18 16:57:58 | [diff] [blame] | 69 | #include "net/url_request/url_request_http_job_histogram.h" |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 70 | #include "net/url_request/url_request_job_factory.h" |
[email protected] | 06965e0 | 2009-09-04 21:36:42 | [diff] [blame] | 71 | #include "net/url_request/url_request_redirect_job.h" |
[email protected] | 6b3f964 | 2010-11-25 02:29:06 | [diff] [blame] | 72 | #include "net/url_request/url_request_throttler_manager.h" |
Bence Béky | a5ec55e6 | 2018-03-07 14:23:28 | [diff] [blame] | 73 | #include "net/url_request/websocket_handshake_userdata_key.h" |
mkwst | 8241a12 | 2015-10-20 07:15:10 | [diff] [blame] | 74 | #include "url/origin.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 75 | |
mgersh | d21d6d14 | 2016-12-14 23:06:36 | [diff] [blame] | 76 | #if defined(OS_ANDROID) |
| 77 | #include "net/android/network_library.h" |
| 78 | #endif |
| 79 | |
mmenke | fd9d15c | 2017-06-29 13:45:54 | [diff] [blame] | 80 | #if BUILDFLAG(ENABLE_REPORTING) |
Julia Tuttle | cba7d22 | 2018-02-23 19:37:27 | [diff] [blame] | 81 | #include "net/network_error_logging/network_error_logging_service.h" |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 82 | #include "net/reporting/reporting_header_parser.h" |
mmenke | fd9d15c | 2017-06-29 13:45:54 | [diff] [blame] | 83 | #include "net/reporting/reporting_service.h" |
| 84 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 85 | |
mkwst | 202534e3 | 2016-01-15 16:07:15 | [diff] [blame] | 86 | namespace { |
| 87 | |
Ryan Sleevi | 19a7bde | 2017-11-22 06:51:39 | [diff] [blame] | 88 | // Records details about the most-specific trust anchor in |spki_hashes|, |
| 89 | // which is expected to be ordered with the leaf cert first and the root cert |
| 90 | // last. This complements the per-verification histogram |
| 91 | // Net.Certificate.TrustAnchor.Verify |
| 92 | void LogTrustAnchor(const net::HashValueVector& spki_hashes) { |
Ryan Sleevi | d756c2d | 2017-12-01 02:07:48 | [diff] [blame] | 93 | // Don't record metrics if there are no hashes; this is true if the HTTP |
| 94 | // load did not come from an active network connection, such as the disk |
| 95 | // cache or a synthesized response. |
| 96 | if (spki_hashes.empty()) |
| 97 | return; |
| 98 | |
Ryan Sleevi | 19a7bde | 2017-11-22 06:51:39 | [diff] [blame] | 99 | int32_t id = 0; |
| 100 | for (const auto& hash : spki_hashes) { |
| 101 | id = net::GetNetTrustAnchorHistogramIdForSPKI(hash); |
| 102 | if (id != 0) |
| 103 | break; |
| 104 | } |
Ilya Sherman | 0eb3980 | 2017-12-08 20:58:18 | [diff] [blame] | 105 | base::UmaHistogramSparse("Net.Certificate.TrustAnchor.Request", id); |
Ryan Sleevi | 19a7bde | 2017-11-22 06:51:39 | [diff] [blame] | 106 | } |
| 107 | |
Emily Stark | 8b411de0 | 2017-11-23 20:21:27 | [diff] [blame] | 108 | // Records per-request histograms relating to Certificate Transparency |
| 109 | // compliance. |
| 110 | void RecordCTHistograms(const net::SSLInfo& ssl_info) { |
Emily Stark | 9676ea8 | 2017-11-29 08:10:08 | [diff] [blame] | 111 | if (ssl_info.ct_policy_compliance == |
| 112 | net::ct::CTPolicyCompliance::CT_POLICY_COMPLIANCE_DETAILS_NOT_AVAILABLE) { |
Emily Stark | 8b411de0 | 2017-11-23 20:21:27 | [diff] [blame] | 113 | return; |
Emily Stark | 9676ea8 | 2017-11-29 08:10:08 | [diff] [blame] | 114 | } |
Emily Stark | 8b411de0 | 2017-11-23 20:21:27 | [diff] [blame] | 115 | if (!ssl_info.is_issued_by_known_root) |
| 116 | return; |
| 117 | |
| 118 | // Connections with major errors other than CERTIFICATE_TRANSPARENCY_REQUIRED |
| 119 | // would have failed anyway, so do not record these histograms for such |
| 120 | // requests. |
| 121 | net::CertStatus other_errors = |
| 122 | ssl_info.cert_status & |
| 123 | ~net::CERT_STATUS_CERTIFICATE_TRANSPARENCY_REQUIRED; |
| 124 | if (net::IsCertStatusError(other_errors) && |
| 125 | !net::IsCertStatusMinorError(other_errors)) { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | // Record the CT compliance of each request, to give a picture of the |
| 130 | // percentage of overall requests that are CT-compliant. |
| 131 | UMA_HISTOGRAM_ENUMERATION( |
| 132 | "Net.CertificateTransparency.RequestComplianceStatus", |
Emily Stark | 627238f | 2017-11-29 03:29:54 | [diff] [blame] | 133 | ssl_info.ct_policy_compliance, |
Kunihiko Sakamoto | 3646973 | 2018-09-27 03:33:45 | [diff] [blame^] | 134 | net::ct::CTPolicyCompliance::CT_POLICY_COUNT); |
Emily Stark | 8b411de0 | 2017-11-23 20:21:27 | [diff] [blame] | 135 | // Record the CT compliance of each request which was required to be CT |
| 136 | // compliant. This gives a picture of the sites that are supposed to be |
| 137 | // compliant and how well they do at actually being compliant. |
| 138 | if (ssl_info.ct_policy_compliance_required) { |
| 139 | UMA_HISTOGRAM_ENUMERATION( |
| 140 | "Net.CertificateTransparency.CTRequiredRequestComplianceStatus", |
Emily Stark | 627238f | 2017-11-29 03:29:54 | [diff] [blame] | 141 | ssl_info.ct_policy_compliance, |
Kunihiko Sakamoto | 3646973 | 2018-09-27 03:33:45 | [diff] [blame^] | 142 | net::ct::CTPolicyCompliance::CT_POLICY_COUNT); |
Emily Stark | 8b411de0 | 2017-11-23 20:21:27 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 146 | // Logs whether the CookieStore used for this request matches the |
| 147 | // ChannelIDService used when establishing the connection that this request is |
| 148 | // sent over. This logging is only done for requests to accounts.google.com, and |
| 149 | // only for requests where Channel ID was sent when establishing the connection. |
nharper | 7923472 | 2016-03-22 20:28:47 | [diff] [blame] | 150 | void LogChannelIDAndCookieStores(const GURL& url, |
| 151 | const net::URLRequestContext* context, |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 152 | const net::SSLInfo& ssl_info) { |
nharper | 7923472 | 2016-03-22 20:28:47 | [diff] [blame] | 153 | if (url.host() != "accounts.google.com" || !ssl_info.channel_id_sent) |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 154 | return; |
| 155 | // This enum is used for an UMA histogram - don't reuse or renumber entries. |
| 156 | enum { |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 157 | // Value 0 was removed (CID_EPHEMERAL_COOKIE_EPHEMERAL) |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 158 | // ChannelIDStore is ephemeral, but CookieStore is persistent. |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 159 | CID_EPHEMERAL_COOKIE_PERSISTENT = 1, |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 160 | // ChannelIDStore is persistent, but CookieStore is ephemeral. |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 161 | CID_PERSISTENT_COOKIE_EPHEMERAL = 2, |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 162 | // Value 3 was removed (CID_PERSISTENT_COOKIE_PERSISTENT) |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 163 | // There is no CookieStore for this request. |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 164 | NO_COOKIE_STORE = 4, |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 165 | // There is no ChannelIDStore for this request. This should never happen, |
| 166 | // because we only log if Channel ID was sent. |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 167 | NO_CHANNEL_ID_STORE = 5, |
nharper | 015b9e4 | 2016-06-29 01:41:52 | [diff] [blame] | 168 | // Value 6 was removed (KNOWN_MISMATCH). |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 169 | // Both stores are ephemeral, and the ChannelIDService used when |
| 170 | // establishing the connection is the same one that the CookieStore was |
| 171 | // created to be used with. |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 172 | EPHEMERAL_MATCH = 7, |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 173 | // Both stores are ephemeral, but a different CookieStore should have been |
| 174 | // used on this request. |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 175 | EPHEMERAL_MISMATCH = 8, |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 176 | // Both stores are persistent, and the ChannelIDService used when |
| 177 | // establishing the connection is the same one that the CookieStore was |
| 178 | // created to be used with. |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 179 | PERSISTENT_MATCH = 9, |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 180 | // Both stores are persistent, but a different CookieStore should have been |
| 181 | // used on this request. |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 182 | PERSISTENT_MISMATCH = 10, |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 183 | // Both stores are ephemeral, but it was never recorded in the CookieStore |
| 184 | // which ChannelIDService it was created for, so it is unknown whether the |
| 185 | // stores match. |
| 186 | EPHEMERAL_UNKNOWN = 11, |
| 187 | // Both stores are persistent, but it was never recorded in the CookieStore |
| 188 | // which ChannelIDService it was created for, so it is unknown whether the |
| 189 | // stores match. |
| 190 | PERSISTENT_UNKNOWN = 12, |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 191 | EPHEMERALITY_MAX |
| 192 | } ephemerality; |
mmenke | 6ddfbea | 2017-05-31 21:48:41 | [diff] [blame] | 193 | const net::HttpNetworkSession::Context* session_context = |
| 194 | context->GetNetworkSessionContext(); |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 195 | net::CookieStore* cookie_store = context->cookie_store(); |
mmenke | 6ddfbea | 2017-05-31 21:48:41 | [diff] [blame] | 196 | if (session_context == nullptr || |
| 197 | session_context->channel_id_service == nullptr) { |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 198 | ephemerality = NO_CHANNEL_ID_STORE; |
| 199 | } else if (cookie_store == nullptr) { |
| 200 | ephemerality = NO_COOKIE_STORE; |
mmenke | 6ddfbea | 2017-05-31 21:48:41 | [diff] [blame] | 201 | } else if (session_context->channel_id_service->GetChannelIDStore() |
| 202 | ->IsEphemeral()) { |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 203 | if (cookie_store->IsEphemeral()) { |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 204 | if (cookie_store->GetChannelIDServiceID() == -1) { |
| 205 | ephemerality = EPHEMERAL_UNKNOWN; |
| 206 | } else if (cookie_store->GetChannelIDServiceID() == |
mmenke | 6ddfbea | 2017-05-31 21:48:41 | [diff] [blame] | 207 | session_context->channel_id_service->GetUniqueID()) { |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 208 | ephemerality = EPHEMERAL_MATCH; |
| 209 | } else { |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 210 | NOTREACHED(); |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 211 | ephemerality = EPHEMERAL_MISMATCH; |
| 212 | } |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 213 | } else { |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 214 | NOTREACHED(); |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 215 | ephemerality = CID_EPHEMERAL_COOKIE_PERSISTENT; |
| 216 | } |
| 217 | } else if (cookie_store->IsEphemeral()) { |
nharper | 4912248 | 2016-04-29 18:00:58 | [diff] [blame] | 218 | NOTREACHED(); |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 219 | ephemerality = CID_PERSISTENT_COOKIE_EPHEMERAL; |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 220 | } else if (cookie_store->GetChannelIDServiceID() == -1) { |
| 221 | ephemerality = PERSISTENT_UNKNOWN; |
| 222 | } else if (cookie_store->GetChannelIDServiceID() == |
mmenke | 6ddfbea | 2017-05-31 21:48:41 | [diff] [blame] | 223 | session_context->channel_id_service->GetUniqueID()) { |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 224 | ephemerality = PERSISTENT_MATCH; |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 225 | } else { |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 226 | NOTREACHED(); |
nharper | 09ccd50 | 2016-03-10 01:54:28 | [diff] [blame] | 227 | ephemerality = PERSISTENT_MISMATCH; |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 228 | } |
| 229 | UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.StoreEphemerality", ephemerality, |
| 230 | EPHEMERALITY_MAX); |
| 231 | } |
| 232 | |
Thiemo Nagel | 0793b9c53 | 2018-04-18 16:57:58 | [diff] [blame] | 233 | net::CookieNetworkSecurity HistogramEntryForCookie( |
| 234 | const net::CanonicalCookie& cookie, |
| 235 | const net::URLRequest& request, |
| 236 | const net::HttpRequestInfo& request_info) { |
| 237 | if (!request_info.url.SchemeIsCryptographic()) { |
| 238 | return net::CookieNetworkSecurity::k1pNonsecureConnection; |
| 239 | } |
| 240 | |
| 241 | if (cookie.IsSecure()) { |
| 242 | return net::CookieNetworkSecurity::k1pSecureAttribute; |
| 243 | } |
| 244 | |
| 245 | net::TransportSecurityState* transport_security_state = |
| 246 | request.context()->transport_security_state(); |
| 247 | net::TransportSecurityState::STSState sts_state; |
| 248 | const std::string cookie_domain = |
| 249 | cookie.IsHostCookie() ? request.url().host() : cookie.Domain().substr(1); |
| 250 | const bool hsts = |
| 251 | transport_security_state->GetSTSState(cookie_domain, &sts_state) && |
| 252 | sts_state.ShouldUpgradeToSSL(); |
| 253 | if (!hsts) { |
| 254 | return net::CookieNetworkSecurity::k1pSecureConnection; |
| 255 | } |
| 256 | |
| 257 | if (cookie.IsHostCookie()) { |
| 258 | if (cookie.IsPersistent() && sts_state.expiry >= cookie.ExpiryDate()) { |
| 259 | return net::CookieNetworkSecurity::k1pHSTSHostCookie; |
| 260 | } else { |
| 261 | // Session cookies are assumed to live forever. |
| 262 | return net::CookieNetworkSecurity::k1pExpiringHSTSHostCookie; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // Domain cookies require HSTS to include subdomains to prevent spoofing. |
| 267 | if (sts_state.include_subdomains) { |
| 268 | if (cookie.IsPersistent() && sts_state.expiry >= cookie.ExpiryDate()) { |
| 269 | return net::CookieNetworkSecurity::k1pHSTSSubdomainsIncluded; |
| 270 | } else { |
| 271 | // Session cookies are assumed to live forever. |
| 272 | return net::CookieNetworkSecurity::k1pExpiringHSTSSubdomainsIncluded; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | return net::CookieNetworkSecurity::k1pHSTSSpoofable; |
| 277 | } |
| 278 | |
Thiemo Nagel | 6c783dbf | 2018-03-21 13:53:30 | [diff] [blame] | 279 | void LogCookieUMA(const net::CookieList& cookie_list, |
| 280 | const net::URLRequest& request, |
| 281 | const net::HttpRequestInfo& request_info) { |
| 282 | const bool secure_request = request_info.url.SchemeIsCryptographic(); |
| 283 | const bool same_site = net::registry_controlled_domains::SameDomainOrHost( |
| 284 | request.url(), request.site_for_cookies(), |
| 285 | net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
Mike West | 8614988 | 2017-07-28 10:41:49 | [diff] [blame] | 286 | |
Thiemo Nagel | 6c783dbf | 2018-03-21 13:53:30 | [diff] [blame] | 287 | const base::Time now = base::Time::Now(); |
| 288 | base::Time oldest = base::Time::Max(); |
| 289 | for (const auto& cookie : cookie_list) { |
| 290 | const std::string histogram_name = |
| 291 | std::string("Cookie.AllAgesFor") + |
| 292 | (secure_request ? "Secure" : "NonSecure") + |
| 293 | (same_site ? "SameSite" : "CrossSite") + "Request"; |
| 294 | const int age_in_days = (now - cookie.CreationDate()).InDays(); |
| 295 | base::UmaHistogramCounts1000(histogram_name, age_in_days); |
Mohsen Izadi | ad6f759 | 2018-04-18 15:57:10 | [diff] [blame] | 296 | oldest = std::min(cookie.CreationDate(), oldest); |
Thiemo Nagel | 0793b9c53 | 2018-04-18 16:57:58 | [diff] [blame] | 297 | |
| 298 | net::CookieNetworkSecurity entry = |
| 299 | HistogramEntryForCookie(cookie, request, request_info); |
| 300 | if (!same_site) { |
| 301 | entry = |
| 302 | static_cast<net::CookieNetworkSecurity>(static_cast<int>(entry) | 1); |
| 303 | } |
| 304 | UMA_HISTOGRAM_ENUMERATION("Cookie.NetworkSecurity", entry, |
| 305 | net::CookieNetworkSecurity::kCount); |
Mike West | 8614988 | 2017-07-28 10:41:49 | [diff] [blame] | 306 | } |
Thiemo Nagel | 6c783dbf | 2018-03-21 13:53:30 | [diff] [blame] | 307 | |
| 308 | const std::string histogram_name = |
| 309 | std::string("Cookie.AgeFor") + (secure_request ? "Secure" : "NonSecure") + |
| 310 | (same_site ? "SameSite" : "CrossSite") + "Request"; |
| 311 | const int age_in_days = (now - oldest).InDays(); |
| 312 | base::UmaHistogramCounts1000(histogram_name, age_in_days); |
Mike West | 8614988 | 2017-07-28 10:41:49 | [diff] [blame] | 313 | } |
| 314 | |
mkwst | 202534e3 | 2016-01-15 16:07:15 | [diff] [blame] | 315 | } // namespace |
| 316 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 317 | namespace net { |
| 318 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 319 | // TODO(darin): make sure the port blocking code is not lost |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 320 | // static |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 321 | URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 322 | NetworkDelegate* network_delegate, |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 323 | const std::string& scheme) { |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 324 | DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || |
| 325 | scheme == "wss"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 326 | |
[email protected] | 81293f48 | 2012-08-13 19:35:45 | [diff] [blame] | 327 | if (!request->context()->http_transaction_factory()) { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 328 | NOTREACHED() << "requires a valid context"; |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 329 | return new URLRequestErrorJob( |
| 330 | request, network_delegate, ERR_INVALID_ARGUMENT); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 331 | } |
| 332 | |
mgersh | d21d6d14 | 2016-12-14 23:06:36 | [diff] [blame] | 333 | const GURL& url = request->url(); |
| 334 | |
| 335 | // Check for reasons not to return a URLRequestHttpJob. These don't apply to |
| 336 | // https and wss requests. |
| 337 | if (!url.SchemeIsCryptographic()) { |
| 338 | // Check for HSTS upgrade. |
| 339 | TransportSecurityState* hsts = |
| 340 | request->context()->transport_security_state(); |
| 341 | if (hsts && hsts->ShouldUpgradeToSSL(url.host())) { |
| 342 | GURL::Replacements replacements; |
| 343 | replacements.SetSchemeStr( |
Mike West | 8614988 | 2017-07-28 10:41:49 | [diff] [blame] | 344 | |
mgersh | d21d6d14 | 2016-12-14 23:06:36 | [diff] [blame] | 345 | url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme : url::kWssScheme); |
| 346 | return new URLRequestRedirectJob( |
| 347 | request, network_delegate, url.ReplaceComponents(replacements), |
| 348 | // Use status code 307 to preserve the method, so POST requests work. |
| 349 | URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); |
| 350 | } |
| 351 | |
| 352 | #if defined(OS_ANDROID) |
| 353 | // Check whether the app allows cleartext traffic to this host, and return |
mgersh | 072720a | 2016-12-15 16:33:34 | [diff] [blame] | 354 | // ERR_CLEARTEXT_NOT_PERMITTED if not. |
mgersh | d21d6d14 | 2016-12-14 23:06:36 | [diff] [blame] | 355 | if (request->context()->check_cleartext_permitted() && |
| 356 | !android::IsCleartextPermitted(url.host())) { |
| 357 | return new URLRequestErrorJob(request, network_delegate, |
| 358 | ERR_CLEARTEXT_NOT_PERMITTED); |
| 359 | } |
| 360 | #endif |
| 361 | } |
mkwst | 549a5c63 | 2016-06-20 14:17:03 | [diff] [blame] | 362 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 363 | return new URLRequestHttpJob(request, |
| 364 | network_delegate, |
| 365 | request->context()->http_user_agent_settings()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 366 | } |
| 367 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 368 | URLRequestHttpJob::URLRequestHttpJob( |
| 369 | URLRequest* request, |
| 370 | NetworkDelegate* network_delegate, |
| 371 | const HttpUserAgentSettings* http_user_agent_settings) |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 372 | : URLRequestJob(request, network_delegate), |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 373 | priority_(DEFAULT_PRIORITY), |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 374 | response_info_(nullptr), |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 375 | proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 376 | server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
[email protected] | 3589e55 | 2008-08-20 23:11:34 | [diff] [blame] | 377 | read_in_progress_(false), |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 378 | throttling_entry_(nullptr), |
[email protected] | 00e48bf | 2010-12-03 06:15:42 | [diff] [blame] | 379 | is_cached_content_(false), |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 380 | packet_timing_enabled_(false), |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 381 | done_(false), |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 382 | bytes_observed_in_packets_(0), |
[email protected] | 5a07c19 | 2012-07-30 20:18:22 | [diff] [blame] | 383 | awaiting_callback_(false), |
[email protected] | 0981210 | 2014-05-24 00:04:11 | [diff] [blame] | 384 | http_user_agent_settings_(http_user_agent_settings), |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 385 | total_received_bytes_from_previous_transactions_(0), |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 386 | total_sent_bytes_from_previous_transactions_(0), |
[email protected] | 0981210 | 2014-05-24 00:04:11 | [diff] [blame] | 387 | weak_factory_(this) { |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 388 | URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 389 | if (manager) |
| 390 | throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 391 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 392 | ResetTimer(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 393 | } |
| 394 | |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 395 | URLRequestHttpJob::~URLRequestHttpJob() { |
| 396 | CHECK(!awaiting_callback_); |
| 397 | |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 398 | DoneWithRequest(ABORTED); |
| 399 | } |
| 400 | |
| 401 | void URLRequestHttpJob::SetPriority(RequestPriority priority) { |
| 402 | priority_ = priority; |
| 403 | if (transaction_) |
| 404 | transaction_->SetPriority(priority_); |
| 405 | } |
| 406 | |
| 407 | void URLRequestHttpJob::Start() { |
| 408 | DCHECK(!transaction_.get()); |
| 409 | |
[email protected] | 99ecf6e | 2013-04-10 22:46:13 | [diff] [blame] | 410 | // URLRequest::SetReferrer ensures that we do not send username and password |
| 411 | // fields in the referrer. |
| 412 | GURL referrer(request_->referrer()); |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 413 | |
| 414 | request_info_.url = request_->url(); |
| 415 | request_info_.method = request_->method(); |
| 416 | request_info_.load_flags = request_->load_flags(); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 417 | request_info_.traffic_annotation = |
| 418 | net::MutableNetworkTrafficAnnotationTag(request_->traffic_annotation()); |
Paul Jensen | 60e4553 | 2018-02-19 16:04:18 | [diff] [blame] | 419 | request_info_.socket_tag = request_->socket_tag(); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 420 | |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 421 | // Enable privacy mode if cookie settings or flags tell us not send or |
| 422 | // save cookies. |
| 423 | bool enable_privacy_mode = |
| 424 | (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) || |
| 425 | (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) || |
| 426 | CanEnablePrivacyMode(); |
mkwst | e3e9599 | 2016-02-23 17:45:41 | [diff] [blame] | 427 | // Privacy mode could still be disabled in SetCookieHeaderAndStart if we are |
| 428 | // going to send previously saved cookies. |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 429 | request_info_.privacy_mode = enable_privacy_mode ? |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 430 | PRIVACY_MODE_ENABLED : PRIVACY_MODE_DISABLED; |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 431 | |
| 432 | // Strip Referer from request_info_.extra_headers to prevent, e.g., plugins |
| 433 | // from overriding headers that are controlled using other means. Otherwise a |
| 434 | // plugin could set a referrer although sending the referrer is inhibited. |
| 435 | request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kReferer); |
| 436 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 437 | // Our consumer should have made sure that this is a safe referrer. See for |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 438 | // instance WebCore::FrameLoader::HideReferrer. |
| 439 | if (referrer.is_valid()) { |
| 440 | request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 441 | referrer.spec()); |
| 442 | } |
| 443 | |
nharper | d6e6582 | 2016-03-30 23:05:48 | [diff] [blame] | 444 | request_info_.token_binding_referrer = request_->token_binding_referrer(); |
| 445 | |
Douglas Creager | f6cb49f7 | 2018-07-19 20:14:53 | [diff] [blame] | 446 | // This should be kept in sync with the corresponding code in |
| 447 | // URLRequest::GetUserAgent. |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 448 | request_info_.extra_headers.SetHeaderIfMissing( |
| 449 | HttpRequestHeaders::kUserAgent, |
| 450 | http_user_agent_settings_ ? |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 451 | http_user_agent_settings_->GetUserAgent() : std::string()); |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 452 | |
| 453 | AddExtraHeaders(); |
| 454 | AddCookieHeaderAndStart(); |
| 455 | } |
| 456 | |
| 457 | void URLRequestHttpJob::Kill() { |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 458 | weak_factory_.InvalidateWeakPtrs(); |
mmenke | 2281f376 | 2015-11-02 20:38:17 | [diff] [blame] | 459 | if (transaction_) |
| 460 | DestroyTransaction(); |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 461 | URLRequestJob::Kill(); |
| 462 | } |
| 463 | |
ttuttle | 3ae0692 | 2015-05-11 23:41:52 | [diff] [blame] | 464 | void URLRequestHttpJob::GetConnectionAttempts(ConnectionAttempts* out) const { |
| 465 | if (transaction_) |
| 466 | transaction_->GetConnectionAttempts(out); |
| 467 | else |
| 468 | out->clear(); |
| 469 | } |
| 470 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 471 | void URLRequestHttpJob::NotifyBeforeSendHeadersCallback( |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 472 | const ProxyInfo& proxy_info, |
| 473 | HttpRequestHeaders* request_headers) { |
| 474 | DCHECK(request_headers); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 475 | DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
Tarun Bansal | 4dcebd4 | 2017-10-12 20:12:30 | [diff] [blame] | 476 | if (proxy_info.is_empty()) { |
| 477 | SetProxyServer(ProxyServer::Direct()); |
| 478 | } else { |
| 479 | SetProxyServer(proxy_info.proxy_server()); |
| 480 | } |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 481 | if (network_delegate()) { |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 482 | network_delegate()->NotifyBeforeSendHeaders( |
| 483 | request_, proxy_info, |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 484 | request_->context()->proxy_resolution_service()->proxy_retry_info(), |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 485 | request_headers); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 489 | void URLRequestHttpJob::NotifyHeadersComplete() { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 490 | DCHECK(!response_info_); |
| 491 | |
| 492 | response_info_ = transaction_->GetResponseInfo(); |
| 493 | |
[email protected] | d8fd513 | 2009-05-15 01:06:53 | [diff] [blame] | 494 | // Save boolean, as we'll need this info at destruction time, and filters may |
| 495 | // also need this info. |
| 496 | is_cached_content_ = response_info_->was_cached; |
| 497 | |
xunjieli | 041e939 | 2015-05-19 21:51:33 | [diff] [blame] | 498 | if (!is_cached_content_ && throttling_entry_.get()) |
| 499 | throttling_entry_->UpdateWithResponse(GetResponseCode()); |
[email protected] | 6b3f964 | 2010-11-25 02:29:06 | [diff] [blame] | 500 | |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 501 | // The ordering of these calls is not important. |
[email protected] | 77f6fb43 | 2009-09-05 14:21:09 | [diff] [blame] | 502 | ProcessStrictTransportSecurityHeader(); |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 503 | ProcessPublicKeyPinsHeader(); |
estark | 1614475f | 2016-03-10 03:46:47 | [diff] [blame] | 504 | ProcessExpectCTHeader(); |
Julia Tuttle | 3f9acac | 2017-11-20 22:06:30 | [diff] [blame] | 505 | #if BUILDFLAG(ENABLE_REPORTING) |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 506 | ProcessReportToHeader(); |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 507 | ProcessNetworkErrorLoggingHeader(); |
Julia Tuttle | 3f9acac | 2017-11-20 22:06:30 | [diff] [blame] | 508 | #endif // BUILDFLAG(ENABLE_REPORTING) |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 509 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 510 | // The HTTP transaction may be restarted several times for the purposes |
| 511 | // of sending authorization information. Each time it restarts, we get |
| 512 | // notified of the headers completion so that we can update the cookie store. |
| 513 | if (transaction_->IsReadyToRestartForAuth()) { |
| 514 | DCHECK(!response_info_->auth_challenge.get()); |
[email protected] | 87a09a9 | 2011-07-14 15:50:50 | [diff] [blame] | 515 | // TODO(battre): This breaks the webrequest API for |
| 516 | // URLRequestTestHTTP.BasicAuthWithCookies |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 517 | // where OnBeforeStartTransaction -> OnStartTransaction -> |
| 518 | // OnBeforeStartTransaction occurs. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 519 | RestartTransactionWithAuth(AuthCredentials()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 520 | return; |
| 521 | } |
| 522 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 523 | URLRequestJob::NotifyHeadersComplete(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 524 | } |
| 525 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 526 | void URLRequestHttpJob::DestroyTransaction() { |
[email protected] | c6a4eb9 | 2010-03-03 23:51:19 | [diff] [blame] | 527 | DCHECK(transaction_.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 528 | |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 529 | DoneWithRequest(ABORTED); |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 530 | |
| 531 | total_received_bytes_from_previous_transactions_ += |
| 532 | transaction_->GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 533 | total_sent_bytes_from_previous_transactions_ += |
| 534 | transaction_->GetTotalSentBytes(); |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 535 | transaction_.reset(); |
David Benjamin | 0bda12f | 2018-02-07 19:58:45 | [diff] [blame] | 536 | response_info_ = nullptr; |
| 537 | override_response_headers_ = nullptr; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 538 | receive_headers_end_ = base::TimeTicks(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 541 | void URLRequestHttpJob::StartTransaction() { |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 542 | if (network_delegate()) { |
David Benjamin | 9776ca2 | 2018-06-13 00:00:15 | [diff] [blame] | 543 | OnCallToDelegate( |
| 544 | NetLogEventType::NETWORK_DELEGATE_BEFORE_START_TRANSACTION); |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 545 | // The NetworkDelegate must watch for OnRequestDestroyed and not modify |
| 546 | // |extra_headers| or invoke the callback after it's called. Not using a |
| 547 | // WeakPtr here because it's not enough, the consumer has to watch for |
| 548 | // destruction regardless, due to the headers parameter. |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 549 | int rv = network_delegate()->NotifyBeforeStartTransaction( |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 550 | request_, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 551 | base::BindOnce(&URLRequestHttpJob::NotifyBeforeStartTransactionCallback, |
| 552 | base::Unretained(this)), |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 553 | &request_info_.extra_headers); |
| 554 | // If an extension blocks the request, we rely on the callback to |
[email protected] | b4438d3 | 2012-09-27 06:15:30 | [diff] [blame] | 555 | // MaybeStartTransactionInternal(). |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 556 | if (rv == ERR_IO_PENDING) |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 557 | return; |
[email protected] | b4438d3 | 2012-09-27 06:15:30 | [diff] [blame] | 558 | MaybeStartTransactionInternal(rv); |
| 559 | return; |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 560 | } |
| 561 | StartTransactionInternal(); |
| 562 | } |
| 563 | |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 564 | void URLRequestHttpJob::NotifyBeforeStartTransactionCallback(int result) { |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 565 | // Check that there are no callbacks to already canceled requests. |
| 566 | DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 567 | |
[email protected] | b4438d3 | 2012-09-27 06:15:30 | [diff] [blame] | 568 | MaybeStartTransactionInternal(result); |
| 569 | } |
| 570 | |
| 571 | void URLRequestHttpJob::MaybeStartTransactionInternal(int result) { |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 572 | OnCallToDelegateComplete(); |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 573 | if (result == OK) { |
| 574 | StartTransactionInternal(); |
| 575 | } else { |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 576 | std::string source("delegate"); |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 577 | request_->net_log().AddEvent(NetLogEventType::CANCELLED, |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 578 | NetLog::StringCallback("source", &source)); |
jam | d3f5a3c | 2016-10-27 18:52:02 | [diff] [blame] | 579 | // Don't call back synchronously to the delegate. |
| 580 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 581 | FROM_HERE, |
| 582 | base::Bind(&URLRequestHttpJob::NotifyStartError, |
| 583 | weak_factory_.GetWeakPtr(), |
| 584 | URLRequestStatus(URLRequestStatus::FAILED, result))); |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | |
| 588 | void URLRequestHttpJob::StartTransactionInternal() { |
mmenke | 4600b60 | 2015-10-28 18:52:17 | [diff] [blame] | 589 | // This should only be called while the request's status is IO_PENDING. |
mmenke | 2281f376 | 2015-11-02 20:38:17 | [diff] [blame] | 590 | DCHECK_EQ(URLRequestStatus::IO_PENDING, request_->status().status()); |
David Benjamin | 0bda12f | 2018-02-07 19:58:45 | [diff] [blame] | 591 | DCHECK(!override_response_headers_); |
mmenke | 4600b60 | 2015-10-28 18:52:17 | [diff] [blame] | 592 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 593 | // NOTE: This method assumes that request_info_ is already setup properly. |
| 594 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 595 | // If we already have a transaction, then we should restart the transaction |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 596 | // with auth provided by auth_credentials_. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 597 | |
[email protected] | 99c0790 | 2010-08-17 18:59:52 | [diff] [blame] | 598 | int rv; |
[email protected] | 6b3f964 | 2010-11-25 02:29:06 | [diff] [blame] | 599 | |
tbansal | 80a5216 | 2016-05-20 17:55:04 | [diff] [blame] | 600 | // Notify NetworkQualityEstimator. |
| 601 | NetworkQualityEstimator* network_quality_estimator = |
| 602 | request()->context()->network_quality_estimator(); |
| 603 | if (network_quality_estimator) |
| 604 | network_quality_estimator->NotifyStartTransaction(*request_); |
| 605 | |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 606 | if (network_delegate()) { |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 607 | network_delegate()->NotifyStartTransaction(request_, |
| 608 | request_info_.extra_headers); |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 609 | } |
| 610 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 611 | if (transaction_.get()) { |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 612 | rv = transaction_->RestartWithAuth( |
| 613 | auth_credentials_, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 614 | base::Unretained(this))); |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 615 | auth_credentials_ = AuthCredentials(); |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 616 | } else { |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 617 | DCHECK(request_->context()->http_transaction_factory()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 618 | |
[email protected] | 99c0790 | 2010-08-17 18:59:52 | [diff] [blame] | 619 | rv = request_->context()->http_transaction_factory()->CreateTransaction( |
[email protected] | 027bd85a | 2013-12-27 22:39:10 | [diff] [blame] | 620 | priority_, &transaction_); |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 621 | |
| 622 | if (rv == OK && request_info_.url.SchemeIsWSOrWSS()) { |
Bence Béky | a5ec55e6 | 2018-03-07 14:23:28 | [diff] [blame] | 623 | base::SupportsUserData::Data* data = |
| 624 | request_->GetUserData(kWebSocketHandshakeUserDataKey); |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 625 | if (data) { |
| 626 | transaction_->SetWebSocketHandshakeStreamCreateHelper( |
| 627 | static_cast<WebSocketHandshakeStreamBase::CreateHelper*>(data)); |
| 628 | } else { |
| 629 | rv = ERR_DISALLOWED_URL_SCHEME; |
| 630 | } |
| 631 | } |
| 632 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 633 | if (rv == OK) { |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 634 | transaction_->SetBeforeHeadersSentCallback( |
| 635 | base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 636 | base::Unretained(this))); |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 637 | transaction_->SetRequestHeadersCallback(request_headers_callback_); |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 638 | transaction_->SetResponseHeadersCallback(response_headers_callback_); |
[email protected] | a45840b | 2014-01-10 15:40:22 | [diff] [blame] | 639 | |
dcheng | c2e01e8 | 2014-08-27 00:24:42 | [diff] [blame] | 640 | if (!throttling_entry_.get() || |
xunjieli | 41edcdd | 2015-06-24 14:26:40 | [diff] [blame] | 641 | !throttling_entry_->ShouldRejectRequest(*request_)) { |
[email protected] | 227b0e8 | 2011-03-25 21:11:53 | [diff] [blame] | 642 | rv = transaction_->Start( |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 643 | &request_info_, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 644 | base::Unretained(this)), |
| 645 | request_->net_log()); |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 646 | start_time_ = base::TimeTicks::Now(); |
[email protected] | 227b0e8 | 2011-03-25 21:11:53 | [diff] [blame] | 647 | } else { |
| 648 | // Special error code for the exponential back-off module. |
| 649 | rv = ERR_TEMPORARILY_THROTTLED; |
| 650 | } |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 651 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 652 | } |
| 653 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 654 | if (rv == ERR_IO_PENDING) |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 655 | return; |
| 656 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 657 | // The transaction started synchronously, but we need to notify the |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 658 | // URLRequest delegate via the message loop. |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 659 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 660 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 661 | weak_factory_.GetWeakPtr(), rv)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 662 | } |
| 663 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 664 | void URLRequestHttpJob::AddExtraHeaders() { |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 665 | if (!request_info_.extra_headers.HasHeader( |
Helen Li | 7dd8083 | 2017-09-12 18:29:17 | [diff] [blame] | 666 | HttpRequestHeaders::kAcceptEncoding)) { |
eustas | fbec913 | 2015-12-30 14:56:51 | [diff] [blame] | 667 | // Advertise "br" encoding only if transferred data is opaque to proxy. |
| 668 | bool advertise_brotli = false; |
eustas | 7ff8968 | 2016-07-07 20:23:39 | [diff] [blame] | 669 | if (request()->context()->enable_brotli()) { |
| 670 | if (request()->url().SchemeIsCryptographic() || |
Rob Wu | f79b3ba | 2018-01-14 01:54:31 | [diff] [blame] | 671 | IsLocalhost(request()->url())) { |
eustas | 7ff8968 | 2016-07-07 20:23:39 | [diff] [blame] | 672 | advertise_brotli = true; |
| 673 | } |
| 674 | } |
eustas | fbec913 | 2015-12-30 14:56:51 | [diff] [blame] | 675 | |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 676 | // Supply Accept-Encoding headers first so that it is more likely that they |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 677 | // will be in the first transmitted packet. This can sometimes make it |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 678 | // easier to filter and analyze the streams to assure that a proxy has not |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 679 | // damaged these headers. Some proxies deliberately corrupt Accept-Encoding |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 680 | // headers. |
eustas | fbec913 | 2015-12-30 14:56:51 | [diff] [blame] | 681 | std::string advertised_encodings = "gzip, deflate"; |
eustas | fbec913 | 2015-12-30 14:56:51 | [diff] [blame] | 682 | if (advertise_brotli) |
| 683 | advertised_encodings += ", br"; |
| 684 | // Tell the server what compression formats are supported. |
| 685 | request_info_.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 686 | advertised_encodings); |
[email protected] | 423041b | 2008-10-27 17:39:28 | [diff] [blame] | 687 | } |
| 688 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 689 | if (http_user_agent_settings_) { |
[email protected] | 84f0543 | 2013-03-15 01:00:12 | [diff] [blame] | 690 | // Only add default Accept-Language if the request didn't have it |
| 691 | // specified. |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 692 | std::string accept_language = |
| 693 | http_user_agent_settings_->GetAcceptLanguage(); |
| 694 | if (!accept_language.empty()) { |
| 695 | request_info_.extra_headers.SetHeaderIfMissing( |
| 696 | HttpRequestHeaders::kAcceptLanguage, |
| 697 | accept_language); |
| 698 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 699 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 700 | } |
| 701 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 702 | void URLRequestHttpJob::AddCookieHeaderAndStart() { |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 703 | CookieStore* cookie_store = request_->context()->cookie_store(); |
[email protected] | 1a6fff5 | 2011-10-20 21:00:16 | [diff] [blame] | 704 | if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { |
mkwst | e3e9599 | 2016-02-23 17:45:41 | [diff] [blame] | 705 | CookieOptions options; |
| 706 | options.set_include_httponly(); |
| 707 | |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 708 | // Set SameSiteCookieMode according to the rules laid out in |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 709 | // https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site: |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 710 | // |
| 711 | // * Include both "strict" and "lax" same-site cookies if the request's |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 712 | // |url|, |initiator|, and |site_for_cookies| all have the same |
clamy | fd58ca07 | 2016-12-21 17:18:32 | [diff] [blame] | 713 | // registrable domain. Note: this also covers the case of a request |
| 714 | // without an initiator (only happens for browser-initiated main frame |
| 715 | // navigations). |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 716 | // |
| 717 | // * Include only "lax" same-site cookies if the request's |URL| and |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 718 | // |site_for_cookies| have the same registrable domain, _and_ the |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 719 | // request's |method| is "safe" ("GET" or "HEAD"). |
| 720 | // |
| 721 | // Note that this will generally be the case only for cross-site requests |
| 722 | // which target a top-level browsing context. |
| 723 | // |
Nasko Oskov | 13105d4 | 2018-03-23 22:02:08 | [diff] [blame] | 724 | // * Include both "strict" and "lax" same-site cookies if the request is |
| 725 | // tagged with a flag allowing it. |
| 726 | // Note that this can be the case for requests initiated by extensions, |
| 727 | // which need to behave as though they are made by the document itself, |
| 728 | // but appear like cross-site ones. |
| 729 | // |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 730 | // * Otherwise, do not include same-site cookies. |
mkwst | c5fa776 | 2016-03-28 09:28:23 | [diff] [blame] | 731 | if (registry_controlled_domains::SameDomainOrHost( |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 732 | request_->url(), request_->site_for_cookies(), |
mkwst | c5fa776 | 2016-03-28 09:28:23 | [diff] [blame] | 733 | registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) { |
clamy | fd58ca07 | 2016-12-21 17:18:32 | [diff] [blame] | 734 | if (!request_->initiator() || |
csharrison | d5c68c49 | 2016-12-03 00:15:27 | [diff] [blame] | 735 | registry_controlled_domains::SameDomainOrHost( |
| 736 | request_->url(), request_->initiator().value().GetURL(), |
Nasko Oskov | 13105d4 | 2018-03-23 22:02:08 | [diff] [blame] | 737 | registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES) || |
| 738 | request_->attach_same_site_cookies()) { |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 739 | options.set_same_site_cookie_mode( |
| 740 | CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
tfarina | dbf45973 | 2017-05-09 04:36:09 | [diff] [blame] | 741 | } else if (HttpUtil::IsMethodSafe(request_->method())) { |
mkwst | f71d0bd | 2016-03-21 14:15:24 | [diff] [blame] | 742 | options.set_same_site_cookie_mode( |
| 743 | CookieOptions::SameSiteCookieMode::INCLUDE_LAX); |
| 744 | } |
mkwst | e3e9599 | 2016-02-23 17:45:41 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | cookie_store->GetCookieListWithOptionsAsync( |
| 748 | request_->url(), options, |
| 749 | base::Bind(&URLRequestHttpJob::SetCookieHeaderAndStart, |
[email protected] | dc8313a | 2014-03-24 21:38:14 | [diff] [blame] | 750 | weak_factory_.GetWeakPtr())); |
[email protected] | 03d845f | 2011-07-29 19:06:26 | [diff] [blame] | 751 | } else { |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 752 | StartTransaction(); |
[email protected] | 03d845f | 2011-07-29 19:06:26 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
mkwst | e3e9599 | 2016-02-23 17:45:41 | [diff] [blame] | 756 | void URLRequestHttpJob::SetCookieHeaderAndStart(const CookieList& cookie_list) { |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 757 | if (!cookie_list.empty() && CanGetCookies(cookie_list)) { |
Thiemo Nagel | 6c783dbf | 2018-03-21 13:53:30 | [diff] [blame] | 758 | LogCookieUMA(cookie_list, *request_, request_info_); |
Mike West | 8614988 | 2017-07-28 10:41:49 | [diff] [blame] | 759 | |
Mike West | 7c8c2ad | 2018-02-10 07:08:49 | [diff] [blame] | 760 | std::string cookie_line = CanonicalCookie::BuildCookieLine(cookie_list); |
| 761 | UMA_HISTOGRAM_COUNTS_10000("Cookie.HeaderLength", cookie_line.length()); |
| 762 | request_info_.extra_headers.SetHeader(HttpRequestHeaders::kCookie, |
| 763 | cookie_line); |
| 764 | |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 765 | // Disable privacy mode as we are sending cookies anyway. |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 766 | request_info_.privacy_mode = PRIVACY_MODE_DISABLED; |
[email protected] | 54f4c936 | 2011-07-25 21:54:46 | [diff] [blame] | 767 | } |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 768 | StartTransaction(); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 769 | } |
| 770 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 771 | void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete(int result) { |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 772 | // End of the call started in OnStartCompleted. |
| 773 | OnCallToDelegateComplete(); |
| 774 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 775 | if (result != OK) { |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 776 | std::string source("delegate"); |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 777 | request_->net_log().AddEvent(NetLogEventType::CANCELLED, |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 778 | NetLog::StringCallback("source", &source)); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 779 | NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 780 | return; |
| 781 | } |
| 782 | |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 783 | base::Time response_date; |
| 784 | if (!GetResponseHeaders()->GetDateValue(&response_date)) |
| 785 | response_date = base::Time(); |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 786 | |
| 787 | if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 788 | request_->context()->cookie_store()) { |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 789 | CookieOptions options; |
| 790 | options.set_include_httponly(); |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 791 | options.set_server_time(response_date); |
jww | 79aceda | 2015-12-07 01:56:34 | [diff] [blame] | 792 | |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 793 | // Set all cookies, without waiting for them to be set. Any subsequent read |
| 794 | // will see the combined result of all cookie operation. |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 795 | const base::StringPiece name("Set-Cookie"); |
Victor Costan | 70f8551 | 2017-11-20 16:14:46 | [diff] [blame] | 796 | std::string cookie_line; |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 797 | size_t iter = 0; |
| 798 | HttpResponseHeaders* headers = GetResponseHeaders(); |
Victor Costan | 70f8551 | 2017-11-20 16:14:46 | [diff] [blame] | 799 | while (headers->EnumerateHeader(&iter, name, &cookie_line)) { |
| 800 | std::unique_ptr<CanonicalCookie> cookie = net::CanonicalCookie::Create( |
| 801 | request_->url(), cookie_line, base::Time::Now(), options); |
| 802 | if (!cookie || !CanSetCookie(*cookie, &options)) |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 803 | continue; |
Randy Smith | e6515d6a | 2018-01-27 03:57:32 | [diff] [blame] | 804 | request_->context()->cookie_store()->SetCookieWithOptionsAsync( |
| 805 | request_->url(), cookie_line, options, |
| 806 | CookieStore::SetCookiesCallback()); |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | |
mmenke | 54e82af | 2016-02-16 23:06:30 | [diff] [blame] | 810 | NotifyHeadersComplete(); |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 811 | } |
| 812 | |
[email protected] | 000d9df0 | 2012-01-18 20:01:46 | [diff] [blame] | 813 | // NOTE: |ProcessStrictTransportSecurityHeader| and |
| 814 | // |ProcessPublicKeyPinsHeader| have very similar structures, by design. |
[email protected] | 77f6fb43 | 2009-09-05 14:21:09 | [diff] [blame] | 815 | void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 816 | DCHECK(response_info_); |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 817 | TransportSecurityState* security_state = |
| 818 | request_->context()->transport_security_state(); |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 819 | const SSLInfo& ssl_info = response_info_->ssl_info; |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 820 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 821 | // Only accept HSTS headers on HTTPS connections that have no |
| 822 | // certificate errors. |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 823 | if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 824 | !security_state) { |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 825 | return; |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 826 | } |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 827 | |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 828 | // Don't accept HSTS headers when the hostname is an IP address. |
| 829 | if (request_info_.url.HostIsIPAddress()) |
| 830 | return; |
| 831 | |
[email protected] | 242d856 | 2012-10-30 21:20:46 | [diff] [blame] | 832 | // http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec: |
| 833 | // |
| 834 | // If a UA receives more than one STS header field in a HTTP response |
| 835 | // message over secure transport, then the UA MUST process only the |
| 836 | // first such header field. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 837 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 838 | std::string value; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 839 | if (headers->EnumerateHeader(nullptr, "Strict-Transport-Security", &value)) |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 840 | security_state->AddHSTSHeader(request_info_.url.host(), value); |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 841 | } |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 842 | |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 843 | void URLRequestHttpJob::ProcessPublicKeyPinsHeader() { |
| 844 | DCHECK(response_info_); |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 845 | TransportSecurityState* security_state = |
| 846 | request_->context()->transport_security_state(); |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 847 | const SSLInfo& ssl_info = response_info_->ssl_info; |
| 848 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 849 | // Only accept HPKP headers on HTTPS connections that have no |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 850 | // certificate errors. |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 851 | if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 852 | !security_state) { |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 853 | return; |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 854 | } |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 855 | |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 856 | // Don't accept HSTS headers when the hostname is an IP address. |
| 857 | if (request_info_.url.HostIsIPAddress()) |
| 858 | return; |
| 859 | |
estark | 53fee7c | 2015-08-03 18:31:51 | [diff] [blame] | 860 | // http://tools.ietf.org/html/rfc7469: |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 861 | // |
| 862 | // If a UA receives more than one PKP header field in an HTTP |
| 863 | // response message over secure transport, then the UA MUST process |
| 864 | // only the first such header field. |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 865 | HttpResponseHeaders* headers = GetResponseHeaders(); |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 866 | std::string value; |
estark | 53fee7c | 2015-08-03 18:31:51 | [diff] [blame] | 867 | if (headers->EnumerateHeader(nullptr, "Public-Key-Pins", &value)) |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 868 | security_state->AddHPKPHeader(request_info_.url.host(), value, ssl_info); |
estark | 53fee7c | 2015-08-03 18:31:51 | [diff] [blame] | 869 | if (headers->EnumerateHeader(nullptr, "Public-Key-Pins-Report-Only", |
| 870 | &value)) { |
| 871 | security_state->ProcessHPKPReportOnlyHeader( |
| 872 | value, HostPortPair::FromURL(request_info_.url), ssl_info); |
| 873 | } |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 874 | } |
| 875 | |
estark | 1614475f | 2016-03-10 03:46:47 | [diff] [blame] | 876 | void URLRequestHttpJob::ProcessExpectCTHeader() { |
| 877 | DCHECK(response_info_); |
| 878 | TransportSecurityState* security_state = |
| 879 | request_->context()->transport_security_state(); |
| 880 | const SSLInfo& ssl_info = response_info_->ssl_info; |
| 881 | |
| 882 | // Only accept Expect CT headers on HTTPS connections that have no |
| 883 | // certificate errors. |
| 884 | if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
| 885 | !security_state) { |
| 886 | return; |
| 887 | } |
| 888 | |
estark | 1614475f | 2016-03-10 03:46:47 | [diff] [blame] | 889 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 890 | std::string value; |
Emily Stark | 4cfecf07 | 2017-08-08 01:05:51 | [diff] [blame] | 891 | if (headers->GetNormalizedHeader("Expect-CT", &value)) { |
estark | 1614475f | 2016-03-10 03:46:47 | [diff] [blame] | 892 | security_state->ProcessExpectCTHeader( |
| 893 | value, HostPortPair::FromURL(request_info_.url), ssl_info); |
| 894 | } |
| 895 | } |
| 896 | |
Julia Tuttle | 3f9acac | 2017-11-20 22:06:30 | [diff] [blame] | 897 | #if BUILDFLAG(ENABLE_REPORTING) |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 898 | void URLRequestHttpJob::ProcessReportToHeader() { |
| 899 | DCHECK(response_info_); |
| 900 | |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 901 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 902 | std::string value; |
| 903 | if (!headers->GetNormalizedHeader("Report-To", &value)) |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 904 | return; |
| 905 | |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 906 | ReportingService* service = request_->context()->reporting_service(); |
| 907 | if (!service) { |
| 908 | ReportingHeaderParser::RecordHeaderDiscardedForNoReportingService(); |
| 909 | return; |
| 910 | } |
| 911 | |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 912 | // Only accept Report-To headers on HTTPS connections that have no |
| 913 | // certificate errors. |
| 914 | // TODO(juliatuttle): Do we need to check cert status? |
| 915 | const SSLInfo& ssl_info = response_info_->ssl_info; |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 916 | if (!ssl_info.is_valid()) { |
| 917 | ReportingHeaderParser::RecordHeaderDiscardedForInvalidSSLInfo(); |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 918 | return; |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 919 | } |
| 920 | if (IsCertStatusError(ssl_info.cert_status)) { |
| 921 | ReportingHeaderParser::RecordHeaderDiscardedForCertStatusError(); |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 922 | return; |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 923 | } |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 924 | |
| 925 | service->ProcessHeader(request_info_.url.GetOrigin(), value); |
| 926 | } |
| 927 | |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 928 | void URLRequestHttpJob::ProcessNetworkErrorLoggingHeader() { |
| 929 | DCHECK(response_info_); |
| 930 | |
| 931 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 932 | std::string value; |
Julia Tuttle | cba7d22 | 2018-02-23 19:37:27 | [diff] [blame] | 933 | if (!headers->GetNormalizedHeader(NetworkErrorLoggingService::kHeaderName, |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 934 | &value)) { |
| 935 | return; |
| 936 | } |
| 937 | |
Julia Tuttle | cba7d22 | 2018-02-23 19:37:27 | [diff] [blame] | 938 | NetworkErrorLoggingService* service = |
| 939 | request_->context()->network_error_logging_service(); |
Julia Tuttle | 36c6dcbf | 2018-03-22 18:02:04 | [diff] [blame] | 940 | if (!service) { |
| 941 | NetworkErrorLoggingService:: |
| 942 | RecordHeaderDiscardedForNoNetworkErrorLoggingService(); |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 943 | return; |
Julia Tuttle | 36c6dcbf | 2018-03-22 18:02:04 | [diff] [blame] | 944 | } |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 945 | |
Julia Tuttle | 36c6dcbf | 2018-03-22 18:02:04 | [diff] [blame] | 946 | // Only accept NEL headers on HTTPS connections that have no certificate |
| 947 | // errors. |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 948 | const SSLInfo& ssl_info = response_info_->ssl_info; |
Julia Tuttle | 36c6dcbf | 2018-03-22 18:02:04 | [diff] [blame] | 949 | if (!ssl_info.is_valid()) { |
| 950 | NetworkErrorLoggingService::RecordHeaderDiscardedForInvalidSSLInfo(); |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 951 | return; |
Julia Tuttle | 36c6dcbf | 2018-03-22 18:02:04 | [diff] [blame] | 952 | } |
| 953 | if (IsCertStatusError(ssl_info.cert_status)) { |
| 954 | NetworkErrorLoggingService::RecordHeaderDiscardedForCertStatusError(); |
| 955 | return; |
| 956 | } |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 957 | |
Douglas Creager | 4d1ef84 | 2018-07-16 23:42:25 | [diff] [blame] | 958 | IPEndPoint endpoint; |
| 959 | if (!GetRemoteEndpoint(&endpoint)) { |
| 960 | NetworkErrorLoggingService::RecordHeaderDiscardedForMissingRemoteEndpoint(); |
| 961 | return; |
| 962 | } |
| 963 | |
| 964 | service->OnHeader(url::Origin::Create(request_info_.url), endpoint.address(), |
| 965 | value); |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 966 | } |
Julia Tuttle | 3f9acac | 2017-11-20 22:06:30 | [diff] [blame] | 967 | #endif // BUILDFLAG(ENABLE_REPORTING) |
Julia Tuttle | f9b7406 | 2017-07-27 14:44:05 | [diff] [blame] | 968 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 969 | void URLRequestHttpJob::OnStartCompleted(int result) { |
xunjieli | 0b7f5b6 | 2016-12-06 20:43:48 | [diff] [blame] | 970 | TRACE_EVENT0(kNetTracingCategory, "URLRequestHttpJob::OnStartCompleted"); |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 971 | RecordTimer(); |
| 972 | |
[email protected] | 80abdad | 2014-03-15 00:20:54 | [diff] [blame] | 973 | // If the job is done (due to cancellation), can just ignore this |
| 974 | // notification. |
| 975 | if (done_) |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 976 | return; |
| 977 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 978 | receive_headers_end_ = base::TimeTicks::Now(); |
| 979 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 980 | const URLRequestContext* context = request_->context(); |
| 981 | |
Ryan Sleevi | 19a7bde | 2017-11-22 06:51:39 | [diff] [blame] | 982 | if (transaction_ && transaction_->GetResponseInfo()) { |
| 983 | const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; |
| 984 | if (!IsCertificateError(result) || |
| 985 | (IsCertStatusError(ssl_info.cert_status) && |
| 986 | IsCertStatusMinorError(ssl_info.cert_status))) { |
| 987 | LogTrustAnchor(ssl_info.public_key_hashes); |
| 988 | } |
Emily Stark | 8b411de0 | 2017-11-23 20:21:27 | [diff] [blame] | 989 | |
| 990 | RecordCTHistograms(ssl_info); |
Ryan Sleevi | 19a7bde | 2017-11-22 06:51:39 | [diff] [blame] | 991 | } |
| 992 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 993 | if (result == OK) { |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 994 | if (transaction_ && transaction_->GetResponseInfo()) { |
| 995 | SetProxyServer(transaction_->GetResponseInfo()->proxy_server); |
| 996 | } |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 997 | scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
hiroshige | cb76caa4c5 | 2015-12-22 07:50:25 | [diff] [blame] | 998 | |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 999 | if (network_delegate()) { |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1000 | // Note that |this| may not be deleted until |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 1001 | // |URLRequestHttpJob::OnHeadersReceivedCallback()| or |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1002 | // |NetworkDelegate::URLRequestDestroyed()| has been called. |
David Benjamin | 9776ca2 | 2018-06-13 00:00:15 | [diff] [blame] | 1003 | OnCallToDelegate(NetLogEventType::NETWORK_DELEGATE_HEADERS_RECEIVED); |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 1004 | allowed_unsafe_redirect_url_ = GURL(); |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 1005 | // The NetworkDelegate must watch for OnRequestDestroyed and not modify |
| 1006 | // any of the arguments or invoke the callback after it's called. Not |
| 1007 | // using a WeakPtr here because it's not enough, the consumer has to watch |
| 1008 | // for destruction regardless, due to the pointer parameters. |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 1009 | int error = network_delegate()->NotifyHeadersReceived( |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 1010 | request_, |
| 1011 | base::BindOnce(&URLRequestHttpJob::OnHeadersReceivedCallback, |
| 1012 | base::Unretained(this)), |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 1013 | headers.get(), &override_response_headers_, |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 1014 | &allowed_unsafe_redirect_url_); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1015 | if (error != OK) { |
| 1016 | if (error == ERR_IO_PENDING) { |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1017 | awaiting_callback_ = true; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1018 | } else { |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 1019 | std::string source("delegate"); |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 1020 | request_->net_log().AddEvent( |
| 1021 | NetLogEventType::CANCELLED, |
| 1022 | NetLog::StringCallback("source", &source)); |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 1023 | OnCallToDelegateComplete(); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1024 | NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); |
| 1025 | } |
| 1026 | return; |
| 1027 | } |
| 1028 | } |
nharper | bafc20f | 2016-03-25 00:40:17 | [diff] [blame] | 1029 | if (transaction_ && transaction_->GetResponseInfo()) { |
| 1030 | LogChannelIDAndCookieStores(request_->url(), request_->context(), |
| 1031 | transaction_->GetResponseInfo()->ssl_info); |
| 1032 | } |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1033 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1034 | SaveCookiesAndNotifyHeadersComplete(OK); |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 1035 | } else if (IsCertificateError(result)) { |
[email protected] | 6061c14 | 2013-10-21 15:13:34 | [diff] [blame] | 1036 | // We encountered an SSL certificate error. |
rsleevi | 9545d34 | 2016-06-21 03:17:37 | [diff] [blame] | 1037 | // Maybe overridable, maybe not. Ask the delegate to decide. |
| 1038 | TransportSecurityState* state = context->transport_security_state(); |
| 1039 | NotifySSLCertificateError( |
| 1040 | transaction_->GetResponseInfo()->ssl_info, |
| 1041 | state->ShouldSSLErrorsBeFatal(request_info_.url.host())); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1042 | } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
[email protected] | a83dd33 | 2011-07-13 10:41:01 | [diff] [blame] | 1043 | NotifyCertificateRequested( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1044 | transaction_->GetResponseInfo()->cert_request_info.get()); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1045 | } else { |
[email protected] | 419704c | 2014-01-14 11:18:06 | [diff] [blame] | 1046 | // Even on an error, there may be useful information in the response |
| 1047 | // info (e.g. whether there's a cached copy). |
| 1048 | if (transaction_.get()) |
| 1049 | response_info_ = transaction_->GetResponseInfo(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1050 | NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 1051 | } |
| 1052 | } |
| 1053 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1054 | void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1055 | awaiting_callback_ = false; |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 1056 | |
| 1057 | // Check that there are no callbacks to already canceled requests. |
| 1058 | DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 1059 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1060 | SaveCookiesAndNotifyHeadersComplete(result); |
| 1061 | } |
| 1062 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1063 | void URLRequestHttpJob::OnReadCompleted(int result) { |
xunjieli | 0b7f5b6 | 2016-12-06 20:43:48 | [diff] [blame] | 1064 | TRACE_EVENT0(kNetTracingCategory, "URLRequestHttpJob::OnReadCompleted"); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1065 | read_in_progress_ = false; |
| 1066 | |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1067 | DCHECK_NE(ERR_IO_PENDING, result); |
| 1068 | |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1069 | if (ShouldFixMismatchedContentLength(result)) |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 1070 | result = OK; |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1071 | |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1072 | // EOF or error, done with this job. |
| 1073 | if (result <= 0) |
| 1074 | DoneWithRequest(FINISHED); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1075 | |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1076 | ReadRawDataComplete(result); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1077 | } |
| 1078 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1079 | void URLRequestHttpJob::RestartTransactionWithAuth( |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 1080 | const AuthCredentials& credentials) { |
| 1081 | auth_credentials_ = credentials; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1082 | |
| 1083 | // These will be reset in OnStartCompleted. |
David Benjamin | 0bda12f | 2018-02-07 19:58:45 | [diff] [blame] | 1084 | response_info_ = nullptr; |
| 1085 | override_response_headers_ = nullptr; // See https://crbug.com/801237. |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1086 | receive_headers_end_ = base::TimeTicks(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1087 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1088 | ResetTimer(); |
| 1089 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1090 | // Update the cookies, since the cookie store may have been updated from the |
| 1091 | // headers in the 401/407. Since cookies were already appended to |
| 1092 | // extra_headers, we need to strip them out before adding them again. |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1093 | request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kCookie); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1094 | |
| 1095 | AddCookieHeaderAndStart(); |
| 1096 | } |
| 1097 | |
[email protected] | 0736d9e | 2012-11-28 19:50:40 | [diff] [blame] | 1098 | void URLRequestHttpJob::SetUpload(UploadDataStream* upload) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1099 | DCHECK(!transaction_.get()) << "cannot change once started"; |
[email protected] | 0736d9e | 2012-11-28 19:50:40 | [diff] [blame] | 1100 | request_info_.upload_data_stream = upload; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | void URLRequestHttpJob::SetExtraRequestHeaders( |
| 1104 | const HttpRequestHeaders& headers) { |
| 1105 | DCHECK(!transaction_.get()) << "cannot change once started"; |
| 1106 | request_info_.extra_headers.CopyFrom(headers); |
| 1107 | } |
| 1108 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1109 | LoadState URLRequestHttpJob::GetLoadState() const { |
| 1110 | return transaction_.get() ? |
| 1111 | transaction_->GetLoadState() : LOAD_STATE_IDLE; |
| 1112 | } |
| 1113 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1114 | bool URLRequestHttpJob::GetMimeType(std::string* mime_type) const { |
| 1115 | DCHECK(transaction_.get()); |
| 1116 | |
| 1117 | if (!response_info_) |
| 1118 | return false; |
| 1119 | |
ellyjones | 0e9d5e8 | 2015-02-17 23:06:28 | [diff] [blame] | 1120 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 1121 | if (!headers) |
| 1122 | return false; |
| 1123 | return headers->GetMimeType(mime_type); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | bool URLRequestHttpJob::GetCharset(std::string* charset) { |
| 1127 | DCHECK(transaction_.get()); |
| 1128 | |
| 1129 | if (!response_info_) |
| 1130 | return false; |
| 1131 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1132 | return GetResponseHeaders()->GetCharset(charset); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | void URLRequestHttpJob::GetResponseInfo(HttpResponseInfo* info) { |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1136 | if (response_info_) { |
[email protected] | 419704c | 2014-01-14 11:18:06 | [diff] [blame] | 1137 | DCHECK(transaction_.get()); |
| 1138 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1139 | *info = *response_info_; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1140 | if (override_response_headers_.get()) |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1141 | info->headers = override_response_headers_; |
| 1142 | } |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1143 | } |
| 1144 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1145 | void URLRequestHttpJob::GetLoadTimingInfo( |
| 1146 | LoadTimingInfo* load_timing_info) const { |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1147 | // If haven't made it far enough to receive any headers, don't return |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 1148 | // anything. This makes for more consistent behavior in the case of errors. |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1149 | if (!transaction_ || receive_headers_end_.is_null()) |
| 1150 | return; |
| 1151 | if (transaction_->GetLoadTimingInfo(load_timing_info)) |
| 1152 | load_timing_info->receive_headers_end = receive_headers_end_; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1153 | } |
| 1154 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1155 | bool URLRequestHttpJob::GetRemoteEndpoint(IPEndPoint* endpoint) const { |
| 1156 | if (!transaction_) |
| 1157 | return false; |
| 1158 | |
| 1159 | return transaction_->GetRemoteEndpoint(endpoint); |
| 1160 | } |
| 1161 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1162 | int URLRequestHttpJob::GetResponseCode() const { |
| 1163 | DCHECK(transaction_.get()); |
| 1164 | |
| 1165 | if (!response_info_) |
| 1166 | return -1; |
| 1167 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1168 | return GetResponseHeaders()->response_code(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1169 | } |
| 1170 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 1171 | void URLRequestHttpJob::PopulateNetErrorDetails( |
| 1172 | NetErrorDetails* details) const { |
| 1173 | if (!transaction_) |
| 1174 | return; |
| 1175 | return transaction_->PopulateNetErrorDetails(details); |
| 1176 | } |
| 1177 | |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1178 | std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1179 | DCHECK(transaction_.get()); |
| 1180 | if (!response_info_) |
Bacek | 8f37155 | 2016-05-12 01:13:49 | [diff] [blame] | 1181 | return nullptr; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1182 | |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1183 | std::unique_ptr<SourceStream> upstream = URLRequestJob::SetUpSourceStream(); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1184 | HttpResponseHeaders* headers = GetResponseHeaders(); |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1185 | std::string type; |
| 1186 | std::vector<SourceStream::SourceType> types; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1187 | size_t iter = 0; |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1188 | while (headers->EnumerateHeader(&iter, "Content-Encoding", &type)) { |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 1189 | SourceStream::SourceType source_type = |
| 1190 | FilterSourceStream::ParseEncodingType(type); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 1191 | switch (source_type) { |
| 1192 | case SourceStream::TYPE_BROTLI: |
| 1193 | case SourceStream::TYPE_DEFLATE: |
| 1194 | case SourceStream::TYPE_GZIP: |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 1195 | types.push_back(source_type); |
| 1196 | break; |
| 1197 | case SourceStream::TYPE_NONE: |
| 1198 | // Identity encoding type. Pass through raw response body. |
| 1199 | return upstream; |
Helen Li | 666c068 | 2017-09-15 19:57:05 | [diff] [blame] | 1200 | case SourceStream::TYPE_UNKNOWN: |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 1201 | // Unknown encoding type. Pass through raw response body. |
| 1202 | // Despite of reporting to UMA, request will not be canceled; though |
| 1203 | // it is expected that user will see malformed / garbage response. |
| 1204 | FilterSourceStream::ReportContentDecodingFailed( |
| 1205 | FilterSourceStream::TYPE_UNKNOWN); |
| 1206 | return upstream; |
Helen Li | 666c068 | 2017-09-15 19:57:05 | [diff] [blame] | 1207 | case SourceStream::TYPE_GZIP_FALLBACK_DEPRECATED: |
| 1208 | case SourceStream::TYPE_SDCH_DEPRECATED: |
| 1209 | case SourceStream::TYPE_SDCH_POSSIBLE_DEPRECATED: |
| 1210 | case SourceStream::TYPE_REJECTED: |
| 1211 | case SourceStream::TYPE_INVALID: |
| 1212 | case SourceStream::TYPE_MAX: |
| 1213 | NOTREACHED(); |
| 1214 | return nullptr; |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 1215 | } |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1216 | } |
| 1217 | |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1218 | for (std::vector<SourceStream::SourceType>::reverse_iterator r_iter = |
| 1219 | types.rbegin(); |
| 1220 | r_iter != types.rend(); ++r_iter) { |
| 1221 | std::unique_ptr<FilterSourceStream> downstream; |
| 1222 | SourceStream::SourceType type = *r_iter; |
| 1223 | switch (type) { |
| 1224 | case SourceStream::TYPE_BROTLI: |
| 1225 | downstream = CreateBrotliSourceStream(std::move(upstream)); |
| 1226 | break; |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1227 | case SourceStream::TYPE_GZIP: |
| 1228 | case SourceStream::TYPE_DEFLATE: |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1229 | downstream = GzipSourceStream::Create(std::move(upstream), type); |
| 1230 | break; |
Helen Li | 666c068 | 2017-09-15 19:57:05 | [diff] [blame] | 1231 | case SourceStream::TYPE_GZIP_FALLBACK_DEPRECATED: |
| 1232 | case SourceStream::TYPE_SDCH_DEPRECATED: |
| 1233 | case SourceStream::TYPE_SDCH_POSSIBLE_DEPRECATED: |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1234 | case SourceStream::TYPE_NONE: |
| 1235 | case SourceStream::TYPE_INVALID: |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 1236 | case SourceStream::TYPE_REJECTED: |
| 1237 | case SourceStream::TYPE_UNKNOWN: |
xunjieli | 28a1877 | 2016-10-25 15:30:06 | [diff] [blame] | 1238 | case SourceStream::TYPE_MAX: |
| 1239 | NOTREACHED(); |
| 1240 | return nullptr; |
| 1241 | } |
| 1242 | if (downstream == nullptr) |
| 1243 | return nullptr; |
| 1244 | upstream = std::move(downstream); |
| 1245 | } |
| 1246 | |
| 1247 | return upstream; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1248 | } |
| 1249 | |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 1250 | bool URLRequestHttpJob::CopyFragmentOnRedirect(const GURL& location) const { |
| 1251 | // Allow modification of reference fragments by default, unless |
| 1252 | // |allowed_unsafe_redirect_url_| is set and equal to the redirect URL. |
| 1253 | // When this is the case, we assume that the network delegate has set the |
| 1254 | // desired redirect URL (with or without fragment), so it must not be changed |
| 1255 | // any more. |
| 1256 | return !allowed_unsafe_redirect_url_.is_valid() || |
| 1257 | allowed_unsafe_redirect_url_ != location; |
| 1258 | } |
| 1259 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1260 | bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 1261 | // HTTP is always safe. |
| 1262 | // TODO(pauljensen): Remove once crbug.com/146591 is fixed. |
| 1263 | if (location.is_valid() && |
| 1264 | (location.scheme() == "http" || location.scheme() == "https")) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1265 | return true; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1266 | } |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 1267 | // Delegates may mark a URL as safe for redirection. |
| 1268 | if (allowed_unsafe_redirect_url_.is_valid() && |
| 1269 | allowed_unsafe_redirect_url_ == location) { |
| 1270 | return true; |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 1271 | } |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 1272 | // Query URLRequestJobFactory as to whether |location| would be safe to |
| 1273 | // redirect to. |
| 1274 | return request_->context()->job_factory() && |
| 1275 | request_->context()->job_factory()->IsSafeRedirectTarget(location); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | bool URLRequestHttpJob::NeedsAuth() { |
| 1279 | int code = GetResponseCode(); |
| 1280 | if (code == -1) |
| 1281 | return false; |
| 1282 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 1283 | // Check if we need either Proxy or WWW Authentication. This could happen |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1284 | // because we either provided no auth info, or provided incorrect info. |
| 1285 | switch (code) { |
| 1286 | case 407: |
| 1287 | if (proxy_auth_state_ == AUTH_STATE_CANCELED) |
| 1288 | return false; |
| 1289 | proxy_auth_state_ = AUTH_STATE_NEED_AUTH; |
| 1290 | return true; |
| 1291 | case 401: |
| 1292 | if (server_auth_state_ == AUTH_STATE_CANCELED) |
| 1293 | return false; |
| 1294 | server_auth_state_ = AUTH_STATE_NEED_AUTH; |
| 1295 | return true; |
| 1296 | } |
| 1297 | return false; |
| 1298 | } |
| 1299 | |
| 1300 | void URLRequestHttpJob::GetAuthChallengeInfo( |
| 1301 | scoped_refptr<AuthChallengeInfo>* result) { |
| 1302 | DCHECK(transaction_.get()); |
| 1303 | DCHECK(response_info_); |
| 1304 | |
| 1305 | // sanity checks: |
| 1306 | DCHECK(proxy_auth_state_ == AUTH_STATE_NEED_AUTH || |
| 1307 | server_auth_state_ == AUTH_STATE_NEED_AUTH); |
[email protected] | 9094b60 | 2012-02-27 21:44:58 | [diff] [blame] | 1308 | DCHECK((GetResponseHeaders()->response_code() == HTTP_UNAUTHORIZED) || |
| 1309 | (GetResponseHeaders()->response_code() == |
| 1310 | HTTP_PROXY_AUTHENTICATION_REQUIRED)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1311 | |
| 1312 | *result = response_info_->auth_challenge; |
| 1313 | } |
| 1314 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 1315 | void URLRequestHttpJob::SetAuth(const AuthCredentials& credentials) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1316 | DCHECK(transaction_.get()); |
| 1317 | |
| 1318 | // Proxy gets set first, then WWW. |
| 1319 | if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { |
| 1320 | proxy_auth_state_ = AUTH_STATE_HAVE_AUTH; |
| 1321 | } else { |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1322 | DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1323 | server_auth_state_ = AUTH_STATE_HAVE_AUTH; |
| 1324 | } |
| 1325 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 1326 | RestartTransactionWithAuth(credentials); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | void URLRequestHttpJob::CancelAuth() { |
| 1330 | // Proxy gets set first, then WWW. |
| 1331 | if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { |
| 1332 | proxy_auth_state_ = AUTH_STATE_CANCELED; |
| 1333 | } else { |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1334 | DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1335 | server_auth_state_ = AUTH_STATE_CANCELED; |
| 1336 | } |
| 1337 | |
| 1338 | // These will be reset in OnStartCompleted. |
| 1339 | response_info_ = NULL; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1340 | receive_headers_end_ = base::TimeTicks::Now(); |
David Benjamin | 0bda12f | 2018-02-07 19:58:45 | [diff] [blame] | 1341 | // TODO(davidben,mmenke): We should either reset override_response_headers_ |
| 1342 | // here or not call NotifyHeadersReceived a second time on the same response |
| 1343 | // headers. See https://crbug.com/810063. |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1344 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1345 | ResetTimer(); |
| 1346 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1347 | // OK, let the consumer read the error page... |
| 1348 | // |
| 1349 | // Because we set the AUTH_STATE_CANCELED flag, NeedsAuth will return false, |
| 1350 | // which will cause the consumer to receive OnResponseStarted instead of |
| 1351 | // OnAuthRequired. |
| 1352 | // |
| 1353 | // We have to do this via InvokeLater to avoid "recursing" the consumer. |
| 1354 | // |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 1355 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1356 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 1357 | weak_factory_.GetWeakPtr(), OK)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | void URLRequestHttpJob::ContinueWithCertificate( |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 1361 | scoped_refptr<X509Certificate> client_cert, |
| 1362 | scoped_refptr<SSLPrivateKey> client_private_key) { |
David Benjamin | 0bda12f | 2018-02-07 19:58:45 | [diff] [blame] | 1363 | DCHECK(transaction_); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1364 | |
| 1365 | DCHECK(!response_info_) << "should not have a response yet"; |
David Benjamin | 0bda12f | 2018-02-07 19:58:45 | [diff] [blame] | 1366 | DCHECK(!override_response_headers_); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1367 | receive_headers_end_ = base::TimeTicks(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1368 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1369 | ResetTimer(); |
| 1370 | |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 1371 | int rv = transaction_->RestartWithCertificate( |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 1372 | std::move(client_cert), std::move(client_private_key), |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 1373 | base::Bind(&URLRequestHttpJob::OnStartCompleted, base::Unretained(this))); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1374 | if (rv == ERR_IO_PENDING) |
| 1375 | return; |
| 1376 | |
| 1377 | // The transaction started synchronously, but we need to notify the |
| 1378 | // URLRequest delegate via the message loop. |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 1379 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1380 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 1381 | weak_factory_.GetWeakPtr(), rv)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | void URLRequestHttpJob::ContinueDespiteLastError() { |
| 1385 | // If the transaction was destroyed, then the job was cancelled. |
| 1386 | if (!transaction_.get()) |
| 1387 | return; |
| 1388 | |
| 1389 | DCHECK(!response_info_) << "should not have a response yet"; |
David Benjamin | 0bda12f | 2018-02-07 19:58:45 | [diff] [blame] | 1390 | DCHECK(!override_response_headers_); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1391 | receive_headers_end_ = base::TimeTicks(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1392 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1393 | ResetTimer(); |
| 1394 | |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 1395 | int rv = transaction_->RestartIgnoringLastError( |
| 1396 | base::Bind(&URLRequestHttpJob::OnStartCompleted, base::Unretained(this))); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1397 | if (rv == ERR_IO_PENDING) |
| 1398 | return; |
| 1399 | |
| 1400 | // The transaction started synchronously, but we need to notify the |
| 1401 | // URLRequest delegate via the message loop. |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 1402 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1403 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 1404 | weak_factory_.GetWeakPtr(), rv)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1405 | } |
| 1406 | |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1407 | bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const { |
| 1408 | // Some servers send the body compressed, but specify the content length as |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 1409 | // the uncompressed size. Although this violates the HTTP spec we want to |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1410 | // support it (as IE and FireFox do), but *only* for an exact match. |
| 1411 | // See http://crbug.com/79694. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1412 | if (rv == ERR_CONTENT_LENGTH_MISMATCH || |
| 1413 | rv == ERR_INCOMPLETE_CHUNKED_ENCODING) { |
mmenke | d3a02b3 | 2016-11-16 20:21:32 | [diff] [blame] | 1414 | if (request_->response_headers()) { |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1415 | int64_t expected_length = |
| 1416 | request_->response_headers()->GetContentLength(); |
pkasting | f527948 | 2016-07-27 02:18:20 | [diff] [blame] | 1417 | VLOG(1) << __func__ << "() \"" << request_->url().spec() << "\"" |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1418 | << " content-length = " << expected_length |
| 1419 | << " pre total = " << prefilter_bytes_read() |
| 1420 | << " post total = " << postfilter_bytes_read(); |
| 1421 | if (postfilter_bytes_read() == expected_length) { |
| 1422 | // Clear the error. |
| 1423 | return true; |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | return false; |
| 1428 | } |
| 1429 | |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1430 | int URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1431 | DCHECK_NE(buf_size, 0); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1432 | DCHECK(!read_in_progress_); |
| 1433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1434 | int rv = transaction_->Read( |
| 1435 | buf, buf_size, |
| 1436 | base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); |
[email protected] | 85c1dce | 2011-07-06 12:01:29 | [diff] [blame] | 1437 | |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1438 | if (ShouldFixMismatchedContentLength(rv)) |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1439 | rv = OK; |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1440 | |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1441 | if (rv == 0 || (rv < 0 && rv != ERR_IO_PENDING)) |
| 1442 | DoneWithRequest(FINISHED); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1443 | |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1444 | if (rv == ERR_IO_PENDING) |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1445 | read_in_progress_ = true; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1446 | |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 1447 | return rv; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | void URLRequestHttpJob::StopCaching() { |
| 1451 | if (transaction_.get()) |
| 1452 | transaction_->StopCaching(); |
| 1453 | } |
| 1454 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 1455 | bool URLRequestHttpJob::GetFullRequestHeaders( |
| 1456 | HttpRequestHeaders* headers) const { |
| 1457 | if (!transaction_) |
| 1458 | return false; |
| 1459 | |
| 1460 | return transaction_->GetFullRequestHeaders(headers); |
| 1461 | } |
| 1462 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1463 | int64_t URLRequestHttpJob::GetTotalReceivedBytes() const { |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 1464 | int64_t total_received_bytes = |
| 1465 | total_received_bytes_from_previous_transactions_; |
| 1466 | if (transaction_) |
| 1467 | total_received_bytes += transaction_->GetTotalReceivedBytes(); |
| 1468 | return total_received_bytes; |
[email protected] | 71e5ff8f | 2014-01-13 09:44:04 | [diff] [blame] | 1469 | } |
| 1470 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1471 | int64_t URLRequestHttpJob::GetTotalSentBytes() const { |
| 1472 | int64_t total_sent_bytes = total_sent_bytes_from_previous_transactions_; |
| 1473 | if (transaction_) |
| 1474 | total_sent_bytes += transaction_->GetTotalSentBytes(); |
| 1475 | return total_sent_bytes; |
| 1476 | } |
| 1477 | |
[email protected] | 5c04f72 | 2011-08-12 17:52:47 | [diff] [blame] | 1478 | void URLRequestHttpJob::DoneReading() { |
[email protected] | e50efea | 2014-03-24 18:41:00 | [diff] [blame] | 1479 | if (transaction_) { |
[email protected] | 5c04f72 | 2011-08-12 17:52:47 | [diff] [blame] | 1480 | transaction_->DoneReading(); |
[email protected] | e50efea | 2014-03-24 18:41:00 | [diff] [blame] | 1481 | } |
| 1482 | DoneWithRequest(FINISHED); |
| 1483 | } |
| 1484 | |
| 1485 | void URLRequestHttpJob::DoneReadingRedirectResponse() { |
| 1486 | if (transaction_) { |
| 1487 | if (transaction_->GetResponseInfo()->headers->IsRedirect(NULL)) { |
| 1488 | // If the original headers indicate a redirect, go ahead and cache the |
| 1489 | // response, even if the |override_response_headers_| are a redirect to |
| 1490 | // another location. |
| 1491 | transaction_->DoneReading(); |
| 1492 | } else { |
| 1493 | // Otherwise, |override_response_headers_| must be non-NULL and contain |
| 1494 | // bogus headers indicating a redirect. |
dcheng | c2e01e8 | 2014-08-27 00:24:42 | [diff] [blame] | 1495 | DCHECK(override_response_headers_.get()); |
[email protected] | e50efea | 2014-03-24 18:41:00 | [diff] [blame] | 1496 | DCHECK(override_response_headers_->IsRedirect(NULL)); |
| 1497 | transaction_->StopCaching(); |
| 1498 | } |
| 1499 | } |
[email protected] | 5c04f72 | 2011-08-12 17:52:47 | [diff] [blame] | 1500 | DoneWithRequest(FINISHED); |
| 1501 | } |
| 1502 | |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1503 | HostPortPair URLRequestHttpJob::GetSocketAddress() const { |
| 1504 | return response_info_ ? response_info_->socket_address : HostPortPair(); |
| 1505 | } |
| 1506 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1507 | void URLRequestHttpJob::RecordTimer() { |
| 1508 | if (request_creation_time_.is_null()) { |
| 1509 | NOTREACHED() |
| 1510 | << "The same transaction shouldn't start twice without new timing."; |
| 1511 | return; |
| 1512 | } |
| 1513 | |
[email protected] | 320a29f1 | 2011-03-21 14:47:41 | [diff] [blame] | 1514 | base::TimeDelta to_start = base::Time::Now() - request_creation_time_; |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1515 | request_creation_time_ = base::Time(); |
[email protected] | 8684a881 | 2011-03-22 13:59:38 | [diff] [blame] | 1516 | |
[email protected] | 5c68d69 | 2011-08-24 04:59:41 | [diff] [blame] | 1517 | UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpTimeToFirstByte", to_start); |
mmenke | 1beda3d | 2016-07-22 03:33:45 | [diff] [blame] | 1518 | if (request_info_.upload_data_stream && |
| 1519 | request_info_.upload_data_stream->size() > 1024 * 1024) { |
| 1520 | UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpTimeToFirstByte.LargeUpload", to_start); |
| 1521 | } |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | void URLRequestHttpJob::ResetTimer() { |
| 1525 | if (!request_creation_time_.is_null()) { |
| 1526 | NOTREACHED() |
| 1527 | << "The timer was reset before it was recorded."; |
| 1528 | return; |
| 1529 | } |
| 1530 | request_creation_time_ = base::Time::Now(); |
| 1531 | } |
| 1532 | |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1533 | void URLRequestHttpJob::UpdatePacketReadTimes() { |
| 1534 | if (!packet_timing_enabled_) |
| 1535 | return; |
| 1536 | |
mmenke | bbf19be2 | 2015-04-11 02:44:48 | [diff] [blame] | 1537 | DCHECK_GT(prefilter_bytes_read(), bytes_observed_in_packets_); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1538 | |
[email protected] | 006ce1a | 2014-07-30 14:41:23 | [diff] [blame] | 1539 | base::Time now(base::Time::Now()); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1540 | if (!bytes_observed_in_packets_) |
[email protected] | 006ce1a | 2014-07-30 14:41:23 | [diff] [blame] | 1541 | request_time_snapshot_ = now; |
| 1542 | final_packet_time_ = now; |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1543 | |
mmenke | bbf19be2 | 2015-04-11 02:44:48 | [diff] [blame] | 1544 | bytes_observed_in_packets_ = prefilter_bytes_read(); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1545 | } |
| 1546 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 1547 | void URLRequestHttpJob::SetRequestHeadersCallback( |
| 1548 | RequestHeadersCallback callback) { |
| 1549 | DCHECK(!transaction_); |
| 1550 | DCHECK(!request_headers_callback_); |
| 1551 | request_headers_callback_ = std::move(callback); |
| 1552 | } |
| 1553 | |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 1554 | void URLRequestHttpJob::SetResponseHeadersCallback( |
| 1555 | ResponseHeadersCallback callback) { |
| 1556 | DCHECK(!transaction_); |
| 1557 | DCHECK(!response_headers_callback_); |
| 1558 | response_headers_callback_ = std::move(callback); |
| 1559 | } |
| 1560 | |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1561 | void URLRequestHttpJob::RecordPerfHistograms(CompletionCause reason) { |
| 1562 | if (start_time_.is_null()) |
| 1563 | return; |
| 1564 | |
| 1565 | base::TimeDelta total_time = base::TimeTicks::Now() - start_time_; |
| 1566 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTime", total_time); |
| 1567 | |
| 1568 | if (reason == FINISHED) { |
Devdeep Ray | 0c6966d | 2017-07-14 00:58:22 | [diff] [blame] | 1569 | UmaHistogramTimes( |
| 1570 | base::StringPrintf("Net.HttpJob.TotalTimeSuccess.Priority%d", |
| 1571 | request()->priority()), |
| 1572 | total_time); |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1573 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeSuccess", total_time); |
| 1574 | } else { |
| 1575 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeCancel", total_time); |
| 1576 | } |
| 1577 | |
[email protected] | 4b4d2024 | 2012-02-23 18:27:46 | [diff] [blame] | 1578 | if (response_info_) { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1579 | // QUIC (by default) supports https scheme only, thus track https URLs only |
| 1580 | // for QUIC. |
| 1581 | bool is_https_google = request() && request()->url().SchemeIs("https") && |
| 1582 | HasGoogleHost(request()->url()); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1583 | bool used_quic = response_info_->DidUseQuic(); |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1584 | if (is_https_google) { |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1585 | if (used_quic) { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1586 | UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpJob.TotalTime.Secure.Quic", |
| 1587 | total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1588 | } |
| 1589 | } |
jkarlin | ded0021b | 2016-12-05 16:01:06 | [diff] [blame] | 1590 | |
| 1591 | UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpJob.PrefilterBytesRead", |
| 1592 | prefilter_bytes_read(), 1, 50000000, 50); |
[email protected] | 4b4d2024 | 2012-02-23 18:27:46 | [diff] [blame] | 1593 | if (response_info_->was_cached) { |
| 1594 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeCached", total_time); |
jkarlin | ded0021b | 2016-12-05 16:01:06 | [diff] [blame] | 1595 | UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpJob.PrefilterBytesRead.Cache", |
| 1596 | prefilter_bytes_read(), 1, 50000000, 50); |
| 1597 | |
jkarlin | cc6943d | 2016-04-25 19:25:35 | [diff] [blame] | 1598 | if (response_info_->unused_since_prefetch) |
Steven Holte | 6143e64 | 2017-06-28 19:47:38 | [diff] [blame] | 1599 | UMA_HISTOGRAM_COUNTS_1M("Net.Prefetch.HitBytes", |
| 1600 | prefilter_bytes_read()); |
jkarlin | cc6943d | 2016-04-25 19:25:35 | [diff] [blame] | 1601 | } else { |
[email protected] | 4b4d2024 | 2012-02-23 18:27:46 | [diff] [blame] | 1602 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeNotCached", total_time); |
jkarlin | ded0021b | 2016-12-05 16:01:06 | [diff] [blame] | 1603 | UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpJob.PrefilterBytesRead.Net", |
| 1604 | prefilter_bytes_read(), 1, 50000000, 50); |
| 1605 | |
| 1606 | if (request_info_.load_flags & LOAD_PREFETCH) { |
Steven Holte | 6143e64 | 2017-06-28 19:47:38 | [diff] [blame] | 1607 | UMA_HISTOGRAM_COUNTS_1M("Net.Prefetch.PrefilterBytesReadFromNetwork", |
| 1608 | prefilter_bytes_read()); |
jkarlin | ded0021b | 2016-12-05 16:01:06 | [diff] [blame] | 1609 | } |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1610 | if (is_https_google) { |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1611 | if (used_quic) { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1612 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 1613 | "Net.HttpJob.TotalTimeNotCached.Secure.Quic", total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1614 | } else { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1615 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 1616 | "Net.HttpJob.TotalTimeNotCached.Secure.NotQuic", total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1617 | } |
| 1618 | } |
[email protected] | b73656ca | 2011-07-22 17:42:17 | [diff] [blame] | 1619 | } |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | start_time_ = base::TimeTicks(); |
| 1623 | } |
| 1624 | |
| 1625 | void URLRequestHttpJob::DoneWithRequest(CompletionCause reason) { |
| 1626 | if (done_) |
| 1627 | return; |
| 1628 | done_ = true; |
tbansal | 79ed5cd | 2015-08-10 18:53:56 | [diff] [blame] | 1629 | |
| 1630 | // Notify NetworkQualityEstimator. |
mmenke | 7ce675a | 2016-11-07 17:08:30 | [diff] [blame] | 1631 | NetworkQualityEstimator* network_quality_estimator = |
| 1632 | request()->context()->network_quality_estimator(); |
| 1633 | if (network_quality_estimator) { |
| 1634 | network_quality_estimator->NotifyRequestCompleted( |
| 1635 | *request(), request_->status().error()); |
tbansal | 79ed5cd | 2015-08-10 18:53:56 | [diff] [blame] | 1636 | } |
| 1637 | |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1638 | RecordPerfHistograms(reason); |
mmenke | 7ce675a | 2016-11-07 17:08:30 | [diff] [blame] | 1639 | request()->set_received_response_content_length(prefilter_bytes_read()); |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1640 | } |
| 1641 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1642 | HttpResponseHeaders* URLRequestHttpJob::GetResponseHeaders() const { |
| 1643 | DCHECK(transaction_.get()); |
| 1644 | DCHECK(transaction_->GetResponseInfo()); |
| 1645 | return override_response_headers_.get() ? |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1646 | override_response_headers_.get() : |
| 1647 | transaction_->GetResponseInfo()->headers.get(); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1651 | awaiting_callback_ = false; |
tbansal | 80a5216 | 2016-05-20 17:55:04 | [diff] [blame] | 1652 | |
| 1653 | // Notify NetworkQualityEstimator. |
mmenke | 7ce675a | 2016-11-07 17:08:30 | [diff] [blame] | 1654 | NetworkQualityEstimator* network_quality_estimator = |
| 1655 | request()->context()->network_quality_estimator(); |
| 1656 | if (network_quality_estimator) |
| 1657 | network_quality_estimator->NotifyURLRequestDestroyed(*request()); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1658 | } |
| 1659 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 1660 | } // namespace net |