blob: 72fafbda81084e3997334cec2415bec1b886b155 [file] [log] [blame]
[email protected]49ed6cc2012-02-02 08:59:161// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d102f542010-06-30 14:51:052// Use of this source code is governed by a BSD-style license that can be
license.botbf09a502008-08-24 00:55:553// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
5#include "net/http/http_network_transaction.h"
6
[email protected]2fbaecf22010-07-22 22:20:357#include <set>
dchengc7eeda422015-12-26 03:56:488#include <utility>
[email protected]2fbaecf22010-07-22 22:20:359#include <vector>
10
nharperb7441ef2016-01-25 23:54:1411#include "base/base64url.h"
[email protected]49639fa2011-12-20 23:22:4112#include "base/bind.h"
danakjdb9ae7942020-11-11 16:01:3513#include "base/callback_helpers.h"
[email protected]68bf9152008-09-25 19:47:3014#include "base/compiler_specific.h"
Rodney Ding329e4bb2021-03-19 22:21:5315#include "base/feature_list.h"
[email protected]270c6412010-03-29 22:02:4716#include "base/format_macros.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/field_trial.h"
David Benjamin5cb91132018-04-06 05:54:4918#include "base/metrics/histogram_functions.h"
asvitkinec3c93722015-06-17 14:48:3719#include "base/metrics/histogram_macros.h"
davidbenf2eaaf92015-05-15 22:18:4220#include "base/metrics/sparse_histogram.h"
[email protected]125ef482013-06-11 18:32:4721#include "base/strings/string_number_conversions.h"
22#include "base/strings/string_util.h"
[email protected]3d498f72013-10-28 21:17:4023#include "base/time/time.h"
[email protected]db74b0102012-05-31 19:55:5324#include "base/values.h"
[email protected]68bf9152008-09-25 19:47:3025#include "build/build_config.h"
[email protected]277d5942010-08-11 21:02:3526#include "net/base/auth.h"
Rodney Ding329e4bb2021-03-19 22:21:5327#include "net/base/features.h"
[email protected]2d6728692011-03-12 01:39:5528#include "net/base/host_port_pair.h"
[email protected]74a85ce2009-02-12 00:03:1929#include "net/base/io_buffer.h"
initial.commit586acc5fe2008-07-26 22:42:5230#include "net/base/load_flags.h"
[email protected]58e32bb2013-01-21 18:23:2531#include "net/base/load_timing_info.h"
[email protected]597cf6e2009-05-29 09:43:2632#include "net/base/net_errors.h"
Lily Houghton582d4622018-01-22 22:43:4033#include "net/base/proxy_server.h"
Titouan Rigoudyba507a882020-07-31 12:15:1534#include "net/base/transport_info.h"
initial.commit586acc5fe2008-07-26 22:42:5235#include "net/base/upload_data_stream.h"
tfarina7a4a7fd2016-01-20 14:23:4436#include "net/base/url_util.h"
Bence Béky230ac612017-08-30 19:17:0837#include "net/cert/cert_status_flags.h"
eustasc7d27da2017-04-06 10:33:2038#include "net/filter/filter_source_stream.h"
bnc5029f4632017-06-08 16:19:0039#include "net/http/bidirectional_stream_impl.h"
[email protected]c3b35c22008-09-27 03:19:4240#include "net/http/http_auth.h"
David Benjamin7c6df0b762021-12-23 21:02:5441#include "net/http/http_auth_controller.h"
[email protected]c3b35c22008-09-27 03:19:4242#include "net/http/http_auth_handler.h"
[email protected]fa82f932010-05-20 11:09:2443#include "net/http/http_auth_handler_factory.h"
[email protected]8d5a34e2009-06-11 21:21:3644#include "net/http/http_basic_stream.h"
initial.commit586acc5fe2008-07-26 22:42:5245#include "net/http/http_chunked_decoder.h"
Eric Roman06bd9742019-07-13 15:19:1346#include "net/http/http_log_util.h"
initial.commit586acc5fe2008-07-26 22:42:5247#include "net/http/http_network_session.h"
[email protected]270c6412010-03-29 22:02:4748#include "net/http/http_request_headers.h"
initial.commit586acc5fe2008-07-26 22:42:5249#include "net/http/http_request_info.h"
[email protected]319d9e6f2009-02-18 19:47:2150#include "net/http/http_response_headers.h"
[email protected]0877e3d2009-10-17 22:29:5751#include "net/http/http_response_info.h"
[email protected]17291a022011-10-10 07:32:5352#include "net/http/http_server_properties.h"
[email protected]9094b602012-02-27 21:44:5853#include "net/http/http_status_code.h"
yhiranoa7e05bb2014-11-06 05:40:3954#include "net/http/http_stream.h"
[email protected]102e27c2011-02-23 01:01:3155#include "net/http/http_stream_factory.h"
initial.commit586acc5fe2008-07-26 22:42:5256#include "net/http/http_util.h"
[email protected]158ac972013-04-19 23:29:2357#include "net/http/transport_security_state.h"
[email protected]d7f16632010-03-29 18:02:3658#include "net/http/url_security_manager.h"
mikecirone8b85c432016-09-08 19:11:0059#include "net/log/net_log_event_type.h"
[email protected]f7984fc62009-06-22 23:26:4460#include "net/socket/client_socket_factory.h"
bnc3472afd2016-11-17 15:27:2161#include "net/socket/next_proto.h"
[email protected]ab739042011-04-07 15:22:2862#include "net/socket/transport_client_socket_pool.h"
Bence Béky94658bf2018-05-11 19:22:5863#include "net/spdy/spdy_http_stream.h"
64#include "net/spdy/spdy_session.h"
65#include "net/spdy/spdy_session_pool.h"
[email protected]536fd0b2013-03-14 17:41:5766#include "net/ssl/ssl_cert_request_info.h"
67#include "net/ssl/ssl_connection_status_flags.h"
Bence Béky230ac612017-08-30 19:17:0868#include "net/ssl/ssl_info.h"
svaldez7872fd02015-11-19 21:10:5469#include "net/ssl/ssl_private_key.h"
[email protected]f89276a72013-07-12 06:41:5470#include "url/gurl.h"
Matt Menkee4399022021-10-21 18:04:4271#include "url/origin.h"
Matt Menkef2ee07c2019-08-29 02:10:3672#include "url/scheme_host_port.h"
[email protected]e69c1cd2014-07-29 07:42:2973#include "url/url_canon.h"
initial.commit586acc5fe2008-07-26 22:42:5274
Douglas Creager3cb042052018-11-06 23:08:5275#if BUILDFLAG(ENABLE_REPORTING)
76#include "net/network_error_logging/network_error_logging_service.h"
Douglas Creager134b52e2018-11-09 18:00:1477#include "net/reporting/reporting_header_parser.h"
78#include "net/reporting/reporting_service.h"
Lily Chenfec60d92019-01-24 01:16:4279#endif // BUILDFLAG(ENABLE_REPORTING)
Douglas Creager3cb042052018-11-06 23:08:5280
Wojciech Dzierżanowskiabdeeaf2019-04-01 20:16:2281namespace net {
82
Biljith Jayan45a41722017-08-16 18:43:1483namespace {
David Benjamin83ddfb32018-03-30 01:07:5284
Biljith Jayan45a41722017-08-16 18:43:1485// Max number of |retry_attempts| (excluding the initial request) after which
86// we give up and show an error page.
87const size_t kMaxRetryAttempts = 2;
David Benjamin83ddfb32018-03-30 01:07:5288
89// Max number of calls to RestartWith* allowed for a single connection. A single
90// HttpNetworkTransaction should not signal very many restartable errors, but it
91// may occur due to a bug (e.g. https://crbug.com/823387 or
92// https://crbug.com/488043) or simply if the server or proxy requests
93// authentication repeatedly. Although these calls are often associated with a
94// user prompt, in other scenarios (remembered preferences, extensions,
95// multi-leg authentication), they may be triggered automatically. To avoid
96// looping forever, bound the number of restarts.
97const size_t kMaxRestarts = 32;
98
Wojciech Dzierżanowskiabdeeaf2019-04-01 20:16:2299void SetProxyInfoInReponse(const ProxyInfo& proxy_info,
100 HttpResponseInfo* response_info) {
101 response_info->was_fetched_via_proxy = !proxy_info.is_direct();
102 if (response_info->was_fetched_via_proxy && !proxy_info.is_empty())
103 response_info->proxy_server = proxy_info.proxy_server();
104 else if (!response_info->was_fetched_via_proxy && proxy_info.is_direct())
105 response_info->proxy_server = ProxyServer::Direct();
106 else
107 response_info->proxy_server = ProxyServer();
108}
Biljith Jayan45a41722017-08-16 18:43:14109
Wojciech Dzierżanowskiabdeeaf2019-04-01 20:16:22110} // namespace
initial.commit586acc5fe2008-07-26 22:42:52111
Victor Costan9c7302b2018-08-27 16:39:44112const int HttpNetworkTransaction::kDrainBodyBufferSize;
113
[email protected]262eec82013-03-19 21:01:36114HttpNetworkTransaction::HttpNetworkTransaction(RequestPriority priority,
115 HttpNetworkSession* session)
[email protected]0757e7702009-03-27 04:00:22116 : pending_auth_target_(HttpAuth::AUTH_NONE),
Bence Béky61f756c2018-04-25 14:17:53117 io_callback_(base::BindRepeating(&HttpNetworkTransaction::OnIOComplete,
118 base::Unretained(this))),
initial.commit586acc5fe2008-07-26 22:42:52119 session_(session),
Raul Tambre94493c652019-03-11 17:18:35120 request_(nullptr),
[email protected]262eec82013-03-19 21:01:36121 priority_(priority),
[email protected]0877e3d2009-10-17 22:29:57122 headers_valid_(false),
Steven Valdezb4ff0412018-01-18 22:39:27123 can_send_early_data_(false),
David Benjaminbac8dff2019-08-07 01:30:41124 configured_client_cert_for_server_(false),
[email protected]b94f92d2010-10-27 16:45:20125 request_headers_(),
Lily Chenfec60d92019-01-24 01:16:42126#if BUILDFLAG(ENABLE_REPORTING)
127 network_error_logging_report_generated_(false),
128 request_reporting_upload_depth_(0),
129#endif // BUILDFLAG(ENABLE_REPORTING)
initial.commit586acc5fe2008-07-26 22:42:52130 read_buf_len_(0),
[email protected]b8015c42013-12-24 15:18:19131 total_received_bytes_(0),
sclittlefb249892015-09-10 21:33:22132 total_sent_bytes_(0),
[email protected]a7ea8832010-07-12 17:54:54133 next_state_(STATE_NONE),
[email protected]831e4a32013-11-14 02:14:44134 establishing_tunnel_(false),
bnc8016c1f2017-03-31 02:11:29135 enable_ip_based_pooling_(true),
bncaccd4962017-04-06 21:00:26136 enable_alternative_services_(true),
Raul Tambre94493c652019-03-11 17:18:35137 websocket_handshake_stream_base_create_helper_(nullptr),
Biljith Jayan45a41722017-08-16 18:43:14138 net_error_details_(),
David Benjamin83ddfb32018-03-30 01:07:52139 retry_attempts_(0),
David Benjamind61bd532019-04-23 21:11:37140 num_restarts_(0) {
Lily Chenfec60d92019-01-24 01:16:42141}
[email protected]3ce7df0f2010-03-03 00:30:50142
[email protected]0b0bf032010-09-21 18:08:50143HttpNetworkTransaction::~HttpNetworkTransaction() {
Lily Chenfec60d92019-01-24 01:16:42144#if BUILDFLAG(ENABLE_REPORTING)
Lily Chend3930e72019-03-01 19:31:11145 // If no error or success report has been generated yet at this point, then
146 // this network transaction was prematurely cancelled.
147 GenerateNetworkErrorLoggingReport(ERR_ABORTED);
Lily Chenfec60d92019-01-24 01:16:42148#endif // BUILDFLAG(ENABLE_REPORTING)
[email protected]0b0bf032010-09-21 18:08:50149 if (stream_.get()) {
[email protected]0b0bf032010-09-21 18:08:50150 // TODO(mbelshe): The stream_ should be able to compute whether or not the
151 // stream should be kept alive. No reason to compute here
152 // and pass it in.
Matt Menke2451c8b2020-12-08 22:42:51153 if (!stream_->CanReuseConnection() || next_state_ != STATE_NONE ||
154 close_connection_on_destruction_) {
[email protected]0b0bf032010-09-21 18:08:50155 stream_->Close(true /* not reusable */);
mmenkebd84c392015-09-02 14:12:34156 } else if (stream_->IsResponseBodyComplete()) {
157 // If the response body is complete, we can just reuse the socket.
158 stream_->Close(false /* reusable */);
[email protected]0b0bf032010-09-21 18:08:50159 } else {
mmenkebd84c392015-09-02 14:12:34160 // Otherwise, we try to drain the response body.
161 HttpStream* stream = stream_.release();
162 stream->Drain(session_);
[email protected]0b0bf032010-09-21 18:08:50163 }
164 }
[email protected]02cad5d2013-10-02 08:14:03165 if (request_ && request_->upload_data_stream)
166 request_->upload_data_stream->Reset(); // Invalidate pending callbacks.
[email protected]0b0bf032010-09-21 18:08:50167}
168
[email protected]684970b2009-08-14 04:54:46169int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info,
Bence Béky046f8c82018-06-12 02:26:04170 CompletionOnceCallback callback,
tfarina42834112016-09-22 13:38:20171 const NetLogWithSource& net_log) {
Batalov Vladislava4e97a502019-04-11 15:35:23172 if (request_info->load_flags & LOAD_ONLY_FROM_CACHE)
173 return ERR_CACHE_MISS;
174
Ramin Halavatib5e433e2018-02-07 07:41:10175 DCHECK(request_info->traffic_annotation.is_valid());
[email protected]9e743cd2010-03-16 07:03:53176 net_log_ = net_log;
[email protected]96d570e42008-08-05 22:43:04177 request_ = request_info;
shivanisha0b440852016-10-18 15:48:15178 url_ = request_->url;
Matt Menkeb32ba5122019-09-10 19:17:05179 network_isolation_key_ = request_->network_isolation_key;
Douglas Creageref5eecdc2018-11-09 20:50:36180#if BUILDFLAG(ENABLE_REPORTING)
Lily Chenfec60d92019-01-24 01:16:42181 // Store values for later use in NEL report generation.
Douglas Creageref5eecdc2018-11-09 20:50:36182 request_method_ = request_->method;
183 request_->extra_headers.GetHeader(HttpRequestHeaders::kReferer,
184 &request_referrer_);
185 request_->extra_headers.GetHeader(HttpRequestHeaders::kUserAgent,
186 &request_user_agent_);
187 request_reporting_upload_depth_ = request_->reporting_upload_depth;
Lily Chenfec60d92019-01-24 01:16:42188 start_timeticks_ = base::TimeTicks::Now();
189#endif // BUILDFLAG(ENABLE_REPORTING)
[email protected]96d570e42008-08-05 22:43:04190
Ryan Sleevi24fe2682018-08-16 21:33:46191 if (request_->load_flags & LOAD_DISABLE_CERT_NETWORK_FETCHES) {
192 server_ssl_config_.disable_cert_verification_network_fetches = true;
193 proxy_ssl_config_.disable_cert_verification_network_fetches = true;
[email protected]99ffa5a2011-10-06 04:20:19194 }
[email protected]6fbac162011-06-20 00:29:04195
Yu Su2d738bb2020-10-30 02:23:55196 if (request_->idempotency == IDEMPOTENT ||
197 (request_->idempotency == DEFAULT_IDEMPOTENCY &&
198 HttpUtil::IsMethodSafe(request_info->method))) {
Steven Valdezb4ff0412018-01-18 22:39:27199 can_send_early_data_ = true;
200 }
201
Dominic Farolino4ecaf0a2019-08-16 06:40:09202 if (request_->load_flags & LOAD_PREFETCH) {
jkarlinfb1d5172015-01-12 14:10:29203 response_.unused_since_prefetch = true;
Dominic Farolino4ecaf0a2019-08-16 06:40:09204 }
205
206 if (request_->load_flags & LOAD_RESTRICTED_PREFETCH) {
207 DCHECK(response_.unused_since_prefetch);
208 response_.restricted_prefetch = true;
209 }
jkarlinfb1d5172015-01-12 14:10:29210
Helen Lib495c3802018-03-30 13:46:09211 next_state_ = STATE_NOTIFY_BEFORE_CREATE_STREAM;
[email protected]96d570e42008-08-05 22:43:04212 int rv = DoLoop(OK);
213 if (rv == ERR_IO_PENDING)
Bence Béky046f8c82018-06-12 02:26:04214 callback_ = std::move(callback);
Lily Chenfec60d92019-01-24 01:16:42215
216 // This always returns ERR_IO_PENDING because DoCreateStream() does, but
217 // GenerateNetworkErrorLoggingReportIfError() should be called here if any
218 // other net::Error can be returned.
219 DCHECK_EQ(rv, ERR_IO_PENDING);
[email protected]96d570e42008-08-05 22:43:04220 return rv;
221}
222
223int HttpNetworkTransaction::RestartIgnoringLastError(
Bence Béky046f8c82018-06-12 02:26:04224 CompletionOnceCallback callback) {
[email protected]8e6441ca2010-08-19 05:56:38225 DCHECK(!stream_.get());
226 DCHECK(!stream_request_.get());
227 DCHECK_EQ(STATE_NONE, next_state_);
228
David Benjamin83ddfb32018-03-30 01:07:52229 if (!CheckMaxRestarts())
230 return ERR_TOO_MANY_RETRIES;
231
[email protected]82918cc2010-08-25 17:24:50232 next_state_ = STATE_CREATE_STREAM;
[email protected]8e6441ca2010-08-19 05:56:38233
[email protected]ccb40e52008-09-17 20:54:40234 int rv = DoLoop(OK);
235 if (rv == ERR_IO_PENDING)
Bence Béky046f8c82018-06-12 02:26:04236 callback_ = std::move(callback);
Lily Chenfec60d92019-01-24 01:16:42237
238 // This always returns ERR_IO_PENDING because DoCreateStream() does, but
239 // GenerateNetworkErrorLoggingReportIfError() should be called here if any
240 // other net::Error can be returned.
241 DCHECK_EQ(rv, ERR_IO_PENDING);
[email protected]aaead502008-10-15 00:20:11242 return rv;
[email protected]96d570e42008-08-05 22:43:04243}
244
[email protected]0b45559b2009-06-12 21:45:11245int HttpNetworkTransaction::RestartWithCertificate(
mattm436ccfe2017-06-19 20:24:08246 scoped_refptr<X509Certificate> client_cert,
247 scoped_refptr<SSLPrivateKey> client_private_key,
Bence Béky046f8c82018-06-12 02:26:04248 CompletionOnceCallback callback) {
David Benjaminbac8dff2019-08-07 01:30:41249 // When we receive ERR_SSL_CLIENT_AUTH_CERT_NEEDED, we always tear down
250 // existing streams and stream requests to force a new connection.
[email protected]8e6441ca2010-08-19 05:56:38251 DCHECK(!stream_request_.get());
252 DCHECK(!stream_.get());
253 DCHECK_EQ(STATE_NONE, next_state_);
254
David Benjamin83ddfb32018-03-30 01:07:52255 if (!CheckMaxRestarts())
256 return ERR_TOO_MANY_RETRIES;
257
David Benjaminbac8dff2019-08-07 01:30:41258 // Add the credentials to the client auth cache. The next stream request will
259 // then pick them up.
260 session_->ssl_client_context()->SetClientCertificate(
mattm436ccfe2017-06-19 20:24:08261 response_.cert_request_info->host_and_port, std::move(client_cert),
262 std::move(client_private_key));
David Benjaminbac8dff2019-08-07 01:30:41263
264 if (!response_.cert_request_info->is_proxy)
265 configured_client_cert_for_server_ = true;
266
[email protected]0b45559b2009-06-12 21:45:11267 // Reset the other member variables.
268 // Note: this is necessary only with SSL renegotiation.
269 ResetStateForRestart();
[email protected]82918cc2010-08-25 17:24:50270 next_state_ = STATE_CREATE_STREAM;
[email protected]0b45559b2009-06-12 21:45:11271 int rv = DoLoop(OK);
272 if (rv == ERR_IO_PENDING)
Bence Béky046f8c82018-06-12 02:26:04273 callback_ = std::move(callback);
Lily Chenfec60d92019-01-24 01:16:42274
275 // This always returns ERR_IO_PENDING because DoCreateStream() does, but
276 // GenerateNetworkErrorLoggingReportIfError() should be called here if any
277 // other net::Error can be returned.
278 DCHECK_EQ(rv, ERR_IO_PENDING);
[email protected]0b45559b2009-06-12 21:45:11279 return rv;
280}
281
Bence Béky046f8c82018-06-12 02:26:04282int HttpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials,
283 CompletionOnceCallback callback) {
David Benjamin83ddfb32018-03-30 01:07:52284 if (!CheckMaxRestarts())
285 return ERR_TOO_MANY_RETRIES;
286
[email protected]0757e7702009-03-27 04:00:22287 HttpAuth::Target target = pending_auth_target_;
288 if (target == HttpAuth::AUTH_NONE) {
289 NOTREACHED();
290 return ERR_UNEXPECTED;
291 }
[email protected]0757e7702009-03-27 04:00:22292 pending_auth_target_ = HttpAuth::AUTH_NONE;
[email protected]c3b35c22008-09-27 03:19:42293
[email protected]f3cf9802011-10-28 18:44:58294 auth_controllers_[target]->ResetAuth(credentials);
[email protected]e772db3f2010-07-12 18:11:13295
[email protected]49639fa2011-12-20 23:22:41296 DCHECK(callback_.is_null());
[email protected]8e6441ca2010-08-19 05:56:38297
298 int rv = OK;
299 if (target == HttpAuth::AUTH_PROXY && establishing_tunnel_) {
300 // In this case, we've gathered credentials for use with proxy
301 // authentication of a tunnel.
[email protected]82918cc2010-08-25 17:24:50302 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
Raul Tambre94493c652019-03-11 17:18:35303 DCHECK(stream_request_ != nullptr);
304 auth_controllers_[target] = nullptr;
[email protected]a7ea8832010-07-12 17:54:54305 ResetStateForRestart();
asanka681f02d2017-02-22 17:06:39306 rv = stream_request_->RestartTunnelWithProxyAuth();
[email protected]a7ea8832010-07-12 17:54:54307 } else {
[email protected]8e6441ca2010-08-19 05:56:38308 // In this case, we've gathered credentials for the server or the proxy
309 // but it is not during the tunneling phase.
Raul Tambre94493c652019-03-11 17:18:35310 DCHECK(stream_request_ == nullptr);
[email protected]a7ea8832010-07-12 17:54:54311 PrepareForAuthRestart(target);
[email protected]8e6441ca2010-08-19 05:56:38312 rv = DoLoop(OK);
Lily Chenfec60d92019-01-24 01:16:42313 // Note: If an error is encountered while draining the old response body, no
314 // Network Error Logging report will be generated, because the error was
315 // with the old request, which will already have had a NEL report generated
316 // for it due to the auth challenge (so we don't report a second error for
317 // that request).
[email protected]a7ea8832010-07-12 17:54:54318 }
[email protected]c3b35c22008-09-27 03:19:42319
[email protected]c3b35c22008-09-27 03:19:42320 if (rv == ERR_IO_PENDING)
Bence Béky046f8c82018-06-12 02:26:04321 callback_ = std::move(callback);
[email protected]c3b35c22008-09-27 03:19:42322 return rv;
[email protected]96d570e42008-08-05 22:43:04323}
324
[email protected]f9ee6b52008-11-08 06:46:23325void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) {
326 DCHECK(HaveAuth(target));
[email protected]8e6441ca2010-08-19 05:56:38327 DCHECK(!stream_request_.get());
328
Bence Béky3238f2e12017-09-22 22:44:49329 // Authorization schemes incompatible with HTTP/2 are unsupported for proxies.
330 if (target == HttpAuth::AUTH_SERVER &&
331 auth_controllers_[target]->NeedsHTTP11()) {
332 session_->http_server_properties()->SetHTTP11Required(
Matt Menked9b24f02019-09-26 17:07:17333 url::SchemeHostPort(request_->url), network_isolation_key_);
Bence Béky3238f2e12017-09-22 22:44:49334 }
335
[email protected]2d2697f92009-02-18 21:00:32336 bool keep_alive = false;
[email protected]0877e3d2009-10-17 22:29:57337 // Even if the server says the connection is keep-alive, we have to be
338 // able to find the end of each response in order to reuse the connection.
mmenkebd84c392015-09-02 14:12:34339 if (stream_->CanReuseConnection()) {
[email protected]0877e3d2009-10-17 22:29:57340 // If the response body hasn't been completely read, we need to drain
341 // it first.
[email protected]351ab642010-08-05 16:55:31342 if (!stream_->IsResponseBodyComplete()) {
[email protected]2d2697f92009-02-18 21:00:32343 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART;
Victor Costan9c7302b2018-08-27 16:39:44344 read_buf_ = base::MakeRefCounted<IOBuffer>(
345 kDrainBodyBufferSize); // A bit bucket.
[email protected]2d2697f92009-02-18 21:00:32346 read_buf_len_ = kDrainBodyBufferSize;
347 return;
348 }
[email protected]0877e3d2009-10-17 22:29:57349 keep_alive = true;
[email protected]37832c6d2009-06-05 19:44:09350 }
351
[email protected]2d2697f92009-02-18 21:00:32352 // We don't need to drain the response body, so we act as if we had drained
353 // the response body.
354 DidDrainBodyForAuthRestart(keep_alive);
355}
356
357void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) {
[email protected]8e6441ca2010-08-19 05:56:38358 DCHECK(!stream_request_.get());
359
360 if (stream_.get()) {
[email protected]b8015c42013-12-24 15:18:19361 total_received_bytes_ += stream_->GetTotalReceivedBytes();
sclittlefb249892015-09-10 21:33:22362 total_sent_bytes_ += stream_->GetTotalSentBytes();
Raul Tambre94493c652019-03-11 17:18:35363 HttpStream* new_stream = nullptr;
mmenkebd84c392015-09-02 14:12:34364 if (keep_alive && stream_->CanReuseConnection()) {
[email protected]8e6441ca2010-08-19 05:56:38365 // We should call connection_->set_idle_time(), but this doesn't occur
366 // often enough to be worth the trouble.
367 stream_->SetConnectionReused();
yhiranoa7e05bb2014-11-06 05:40:39368 new_stream = stream_->RenewStreamForAuth();
[email protected]8e6441ca2010-08-19 05:56:38369 }
[email protected]697ef4c2010-10-14 16:38:58370
371 if (!new_stream) {
[email protected]2d0a4f92011-05-05 16:38:46372 // Close the stream and mark it as not_reusable. Even in the
373 // keep_alive case, we've determined that the stream_ is not
374 // reusable if new_stream is NULL.
375 stream_->Close(true);
[email protected]697ef4c2010-10-14 16:38:58376 next_state_ = STATE_CREATE_STREAM;
377 } else {
sclittlefb249892015-09-10 21:33:22378 // Renewed streams shouldn't carry over sent or received bytes.
[email protected]b8015c42013-12-24 15:18:19379 DCHECK_EQ(0, new_stream->GetTotalReceivedBytes());
sclittlefb249892015-09-10 21:33:22380 DCHECK_EQ(0, new_stream->GetTotalSentBytes());
[email protected]697ef4c2010-10-14 16:38:58381 next_state_ = STATE_INIT_STREAM;
382 }
383 stream_.reset(new_stream);
[email protected]2d2697f92009-02-18 21:00:32384 }
[email protected]f9ee6b52008-11-08 06:46:23385
386 // Reset the other member variables.
[email protected]697ef4c2010-10-14 16:38:58387 ResetStateForAuthRestart();
[email protected]f9ee6b52008-11-08 06:46:23388}
389
[email protected]8e6441ca2010-08-19 05:56:38390bool HttpNetworkTransaction::IsReadyToRestartForAuth() {
391 return pending_auth_target_ != HttpAuth::AUTH_NONE &&
392 HaveAuth(pending_auth_target_);
393}
394
Bence Béky046f8c82018-06-12 02:26:04395int HttpNetworkTransaction::Read(IOBuffer* buf,
396 int buf_len,
397 CompletionOnceCallback callback) {
[email protected]96d570e42008-08-05 22:43:04398 DCHECK(buf);
[email protected]e0c27be2009-07-15 13:09:35399 DCHECK_LT(0, buf_len);
[email protected]96d570e42008-08-05 22:43:04400
[email protected]ad8e04a2010-11-01 04:16:27401 scoped_refptr<HttpResponseHeaders> headers(GetResponseHeaders());
[email protected]8e6441ca2010-08-19 05:56:38402 if (headers_valid_ && headers.get() && stream_request_.get()) {
[email protected]8a1f3312010-05-25 19:25:04403 // We're trying to read the body of the response but we're still trying
[email protected]511f6f52010-12-17 03:58:29404 // to establish an SSL tunnel through an HTTP proxy. We can't read these
[email protected]8a1f3312010-05-25 19:25:04405 // bytes when establishing a tunnel because they might be controlled by
406 // an active network attacker. We don't worry about this for HTTP
407 // because an active network attacker can already control HTTP sessions.
[email protected]511f6f52010-12-17 03:58:29408 // We reach this case when the user cancels a 407 proxy auth prompt. We
409 // also don't worry about this for an HTTPS Proxy, because the
410 // communication with the proxy is secure.
[email protected]8a1f3312010-05-25 19:25:04411 // See http://crbug.com/8473.
Eric Romandbf7441f2020-07-28 07:05:02412 DCHECK(proxy_info_.is_http_like());
[email protected]9094b602012-02-27 21:44:58413 DCHECK_EQ(headers->response_code(), HTTP_PROXY_AUTHENTICATION_REQUIRED);
[email protected]8a1f3312010-05-25 19:25:04414 return ERR_TUNNEL_CONNECTION_FAILED;
[email protected]a8e9b162009-03-12 00:06:44415 }
416
[email protected]e60e47a2010-07-14 03:37:18417 // Are we using SPDY or HTTP?
shivanisha0b440852016-10-18 15:48:15418 next_state_ = STATE_READ_BODY;
419
[email protected]96d570e42008-08-05 22:43:04420 read_buf_ = buf;
421 read_buf_len_ = buf_len;
422
[email protected]96d570e42008-08-05 22:43:04423 int rv = DoLoop(OK);
424 if (rv == ERR_IO_PENDING)
Bence Béky046f8c82018-06-12 02:26:04425 callback_ = std::move(callback);
[email protected]96d570e42008-08-05 22:43:04426 return rv;
427}
428
[email protected]8cd06c02014-01-25 07:50:14429void HttpNetworkTransaction::StopCaching() {}
430
sclittle4de1bab92015-09-22 21:28:24431int64_t HttpNetworkTransaction::GetTotalReceivedBytes() const {
432 int64_t total_received_bytes = total_received_bytes_;
[email protected]b8015c42013-12-24 15:18:19433 if (stream_)
434 total_received_bytes += stream_->GetTotalReceivedBytes();
435 return total_received_bytes;
436}
437
sclittlefb249892015-09-10 21:33:22438int64_t HttpNetworkTransaction::GetTotalSentBytes() const {
439 int64_t total_sent_bytes = total_sent_bytes_;
440 if (stream_)
441 total_sent_bytes += stream_->GetTotalSentBytes();
442 return total_sent_bytes;
443}
444
[email protected]8cd06c02014-01-25 07:50:14445void HttpNetworkTransaction::DoneReading() {}
446
[email protected]96d570e42008-08-05 22:43:04447const HttpResponseInfo* HttpNetworkTransaction::GetResponseInfo() const {
ttuttlec0c828492015-05-15 01:25:55448 return &response_;
[email protected]96d570e42008-08-05 22:43:04449}
450
451LoadState HttpNetworkTransaction::GetLoadState() const {
452 // TODO(wtc): Define a new LoadState value for the
453 // STATE_INIT_CONNECTION_COMPLETE state, which delays the HTTP request.
454 switch (next_state_) {
[email protected]1826a402014-01-08 15:40:48455 case STATE_CREATE_STREAM:
456 return LOAD_STATE_WAITING_FOR_DELEGATE;
[email protected]82918cc2010-08-25 17:24:50457 case STATE_CREATE_STREAM_COMPLETE:
[email protected]8e6441ca2010-08-19 05:56:38458 return stream_request_->GetLoadState();
[email protected]044de0642010-06-17 10:42:15459 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE:
460 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE:
[email protected]0877e3d2009-10-17 22:29:57461 case STATE_SEND_REQUEST_COMPLETE:
[email protected]96d570e42008-08-05 22:43:04462 return LOAD_STATE_SENDING_REQUEST;
463 case STATE_READ_HEADERS_COMPLETE:
464 return LOAD_STATE_WAITING_FOR_RESPONSE;
465 case STATE_READ_BODY_COMPLETE:
466 return LOAD_STATE_READING_RESPONSE;
467 default:
468 return LOAD_STATE_IDLE;
469 }
470}
471
[email protected]8cd06c02014-01-25 07:50:14472void HttpNetworkTransaction::SetQuicServerInfo(
473 QuicServerInfo* quic_server_info) {}
474
[email protected]5033ab82013-03-22 20:17:46475bool HttpNetworkTransaction::GetLoadTimingInfo(
476 LoadTimingInfo* load_timing_info) const {
477 if (!stream_ || !stream_->GetLoadTimingInfo(load_timing_info))
478 return false;
479
480 load_timing_info->proxy_resolve_start =
481 proxy_info_.proxy_resolve_start_time();
482 load_timing_info->proxy_resolve_end = proxy_info_.proxy_resolve_end_time();
483 load_timing_info->send_start = send_start_time_;
484 load_timing_info->send_end = send_end_time_;
[email protected]5033ab82013-03-22 20:17:46485 return true;
486}
487
ttuttled9dbc652015-09-29 20:00:59488bool HttpNetworkTransaction::GetRemoteEndpoint(IPEndPoint* endpoint) const {
thestiga74ad2b2016-07-11 20:52:36489 if (remote_endpoint_.address().empty())
ttuttled9dbc652015-09-29 20:00:59490 return false;
491
492 *endpoint = remote_endpoint_;
493 return true;
494}
495
zhongyi48704c182015-12-07 07:52:02496void HttpNetworkTransaction::PopulateNetErrorDetails(
497 NetErrorDetails* details) const {
zhongyica364fbb2015-12-12 03:39:12498 *details = net_error_details_;
499 if (stream_)
500 stream_->PopulateNetErrorDetails(details);
zhongyi48704c182015-12-07 07:52:02501}
502
[email protected]5033ab82013-03-22 20:17:46503void HttpNetworkTransaction::SetPriority(RequestPriority priority) {
504 priority_ = priority;
rdsmith1d343be52016-10-21 20:37:50505
[email protected]bf828982013-08-14 18:01:47506 if (stream_request_)
507 stream_request_->SetPriority(priority);
[email protected]e86839fd2013-08-14 18:29:03508 if (stream_)
509 stream_->SetPriority(priority);
rdsmith1d343be52016-10-21 20:37:50510
rdsmith1d343be52016-10-21 20:37:50511 // The above call may have resulted in deleting |*this|.
[email protected]5033ab82013-03-22 20:17:46512}
513
[email protected]831e4a32013-11-14 02:14:44514void HttpNetworkTransaction::SetWebSocketHandshakeStreamCreateHelper(
515 WebSocketHandshakeStreamBase::CreateHelper* create_helper) {
516 websocket_handshake_stream_base_create_helper_ = create_helper;
517}
518
[email protected]1826a402014-01-08 15:40:48519void HttpNetworkTransaction::SetBeforeNetworkStartCallback(
Will Cassella61125f92020-07-25 09:11:37520 BeforeNetworkStartCallback callback) {
521 before_network_start_callback_ = std::move(callback);
[email protected]1826a402014-01-08 15:40:48522}
523
Titouan Rigoudy78af7da2020-07-07 14:30:12524void HttpNetworkTransaction::SetConnectedCallback(
525 const ConnectedCallback& callback) {
526 connected_callback_ = callback;
527}
528
Andrey Kosyakov83a6eee2017-08-14 19:20:04529void HttpNetworkTransaction::SetRequestHeadersCallback(
530 RequestHeadersCallback callback) {
531 DCHECK(!stream_);
532 request_headers_callback_ = std::move(callback);
533}
534
Kenichi Ishibashi74155532021-03-13 01:38:06535void HttpNetworkTransaction::SetEarlyResponseHeadersCallback(
536 ResponseHeadersCallback callback) {
537 DCHECK(!stream_);
538 early_response_headers_callback_ = std::move(callback);
539}
540
Andrey Kosyakov2e893e62017-08-31 17:00:52541void HttpNetworkTransaction::SetResponseHeadersCallback(
542 ResponseHeadersCallback callback) {
543 DCHECK(!stream_);
544 response_headers_callback_ = std::move(callback);
545}
546
[email protected]1826a402014-01-08 15:40:48547int HttpNetworkTransaction::ResumeNetworkStart() {
548 DCHECK_EQ(next_state_, STATE_CREATE_STREAM);
549 return DoLoop(OK);
550}
551
Aaron Tagliaboschib35cc402021-03-10 22:23:32552void HttpNetworkTransaction::ResumeAfterConnected(int result) {
553 DCHECK_EQ(next_state_, STATE_CONNECTED_CALLBACK_COMPLETE);
554 OnIOComplete(result);
555}
556
Matt Menke2451c8b2020-12-08 22:42:51557void HttpNetworkTransaction::CloseConnectionOnDestruction() {
558 close_connection_on_destruction_ = true;
559}
560
[email protected]102e27c2011-02-23 01:01:31561void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config,
562 const ProxyInfo& used_proxy_info,
bnc5029f4632017-06-08 16:19:00563 std::unique_ptr<HttpStream> stream) {
[email protected]82918cc2010-08-25 17:24:50564 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38565 DCHECK(stream_request_.get());
566
sclittlefb249892015-09-10 21:33:22567 if (stream_) {
[email protected]b8015c42013-12-24 15:18:19568 total_received_bytes_ += stream_->GetTotalReceivedBytes();
sclittlefb249892015-09-10 21:33:22569 total_sent_bytes_ += stream_->GetTotalSentBytes();
570 }
bnc5029f4632017-06-08 16:19:00571 stream_ = std::move(stream);
Andrey Kosyakov83a6eee2017-08-14 19:20:04572 stream_->SetRequestHeadersCallback(request_headers_callback_);
[email protected]102957f2011-09-02 17:10:14573 server_ssl_config_ = used_ssl_config;
[email protected]102e27c2011-02-23 01:01:31574 proxy_info_ = used_proxy_info;
bnc94c92842016-09-21 15:22:52575 response_.was_alpn_negotiated = stream_request_->was_alpn_negotiated();
bnc3472afd2016-11-17 15:27:21576 response_.alpn_negotiated_protocol =
577 NextProtoToString(stream_request_->negotiated_protocol());
[email protected]8e6441ca2010-08-19 05:56:38578 response_.was_fetched_via_spdy = stream_request_->using_spdy();
Cammie Smith Barnesbf91e2a2020-12-23 20:49:04579 response_.dns_aliases = stream_->GetDnsAliases();
Wojciech Dzierżanowskiabdeeaf2019-04-01 20:16:22580 SetProxyInfoInReponse(used_proxy_info, &response_);
[email protected]8e6441ca2010-08-19 05:56:38581 OnIOComplete(OK);
582}
583
xunjieli5749218c2016-03-22 16:43:06584void HttpNetworkTransaction::OnBidirectionalStreamImplReady(
xunjieli11834f02015-12-22 04:27:08585 const SSLConfig& used_ssl_config,
586 const ProxyInfo& used_proxy_info,
bnc5029f4632017-06-08 16:19:00587 std::unique_ptr<BidirectionalStreamImpl> stream) {
xunjieli11834f02015-12-22 04:27:08588 NOTREACHED();
589}
590
[email protected]a9cf2b92013-10-30 12:08:49591void HttpNetworkTransaction::OnWebSocketHandshakeStreamReady(
[email protected]3732cea2013-06-21 06:50:50592 const SSLConfig& used_ssl_config,
593 const ProxyInfo& used_proxy_info,
bnc5029f4632017-06-08 16:19:00594 std::unique_ptr<WebSocketHandshakeStreamBase> stream) {
595 OnStreamReady(used_ssl_config, used_proxy_info, std::move(stream));
[email protected]3732cea2013-06-21 06:50:50596}
597
Ryan Hamilton75f197262017-08-17 14:00:07598void HttpNetworkTransaction::OnStreamFailed(
599 int result,
600 const NetErrorDetails& net_error_details,
Wojciech Dzierżanowskiabdeeaf2019-04-01 20:16:22601 const SSLConfig& used_ssl_config,
dalyk6d7a8c52019-12-18 21:43:01602 const ProxyInfo& used_proxy_info,
603 ResolveErrorInfo resolve_error_info) {
[email protected]82918cc2010-08-25 17:24:50604 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38605 DCHECK_NE(OK, result);
606 DCHECK(stream_request_.get());
607 DCHECK(!stream_.get());
[email protected]102957f2011-09-02 17:10:14608 server_ssl_config_ = used_ssl_config;
Ryan Hamilton75f197262017-08-17 14:00:07609 net_error_details_ = net_error_details;
Wojciech Dzierżanowskiabdeeaf2019-04-01 20:16:22610 proxy_info_ = used_proxy_info;
611 SetProxyInfoInReponse(used_proxy_info, &response_);
dalyk6d7a8c52019-12-18 21:43:01612 response_.resolve_error_info = resolve_error_info;
[email protected]8e6441ca2010-08-19 05:56:38613
614 OnIOComplete(result);
615}
616
[email protected]102e27c2011-02-23 01:01:31617void HttpNetworkTransaction::OnCertificateError(
618 int result,
619 const SSLConfig& used_ssl_config,
620 const SSLInfo& ssl_info) {
[email protected]82918cc2010-08-25 17:24:50621 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38622 DCHECK_NE(OK, result);
623 DCHECK(stream_request_.get());
624 DCHECK(!stream_.get());
625
626 response_.ssl_info = ssl_info;
[email protected]102957f2011-09-02 17:10:14627 server_ssl_config_ = used_ssl_config;
[email protected]8e6441ca2010-08-19 05:56:38628
629 // TODO(mbelshe): For now, we're going to pass the error through, and that
630 // will close the stream_request in all cases. This means that we're always
[email protected]82918cc2010-08-25 17:24:50631 // going to restart an entire STATE_CREATE_STREAM, even if the connection is
632 // good and the user chooses to ignore the error. This is not ideal, but not
633 // the end of the world either.
[email protected]8e6441ca2010-08-19 05:56:38634
635 OnIOComplete(result);
636}
637
638void HttpNetworkTransaction::OnNeedsProxyAuth(
[email protected]6dc476da2010-09-01 04:43:50639 const HttpResponseInfo& proxy_response,
[email protected]102e27c2011-02-23 01:01:31640 const SSLConfig& used_ssl_config,
641 const ProxyInfo& used_proxy_info,
[email protected]6dc476da2010-09-01 04:43:50642 HttpAuthController* auth_controller) {
[email protected]8e6441ca2010-08-19 05:56:38643 DCHECK(stream_request_.get());
[email protected]82918cc2010-08-25 17:24:50644 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38645
646 establishing_tunnel_ = true;
647 response_.headers = proxy_response.headers;
648 response_.auth_challenge = proxy_response.auth_challenge;
Wojciech Dzierżanowski0950c372019-04-02 19:29:50649 response_.did_use_http_auth = proxy_response.did_use_http_auth;
Wojciech Dzierżanowski758b4fb2021-04-19 23:26:59650 SetProxyInfoInReponse(used_proxy_info, &response_);
eustasc7d27da2017-04-06 10:33:20651
Matt Menke48f5f2d02021-02-11 18:54:26652 if (!ContentEncodingsValid()) {
eustasc7d27da2017-04-06 10:33:20653 DoCallback(ERR_CONTENT_DECODING_FAILED);
654 return;
655 }
656
[email protected]8e6441ca2010-08-19 05:56:38657 headers_valid_ = true;
[email protected]102957f2011-09-02 17:10:14658 server_ssl_config_ = used_ssl_config;
[email protected]102e27c2011-02-23 01:01:31659 proxy_info_ = used_proxy_info;
[email protected]8e6441ca2010-08-19 05:56:38660
661 auth_controllers_[HttpAuth::AUTH_PROXY] = auth_controller;
662 pending_auth_target_ = HttpAuth::AUTH_PROXY;
663
664 DoCallback(OK);
665}
666
667void HttpNetworkTransaction::OnNeedsClientAuth(
[email protected]102e27c2011-02-23 01:01:31668 const SSLConfig& used_ssl_config,
[email protected]6dc476da2010-09-01 04:43:50669 SSLCertRequestInfo* cert_info) {
[email protected]82918cc2010-08-25 17:24:50670 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38671
[email protected]102957f2011-09-02 17:10:14672 server_ssl_config_ = used_ssl_config;
[email protected]8e6441ca2010-08-19 05:56:38673 response_.cert_request_info = cert_info;
[email protected]65a3b912010-08-21 05:46:58674 OnIOComplete(ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]8e6441ca2010-08-19 05:56:38675}
676
zhongyi48704c182015-12-07 07:52:02677void HttpNetworkTransaction::OnQuicBroken() {
zhongyica364fbb2015-12-12 03:39:12678 net_error_details_.quic_broken = true;
zhongyi48704c182015-12-07 07:52:02679}
680
ttuttle1f2d7e92015-04-28 16:17:47681void HttpNetworkTransaction::GetConnectionAttempts(
682 ConnectionAttempts* out) const {
683 *out = connection_attempts_;
684}
685
Adam Ricecb76ac62015-02-20 05:33:25686bool HttpNetworkTransaction::IsSecureRequest() const {
lgarrona774b922015-05-14 22:56:37687 return request_->url.SchemeIsCryptographic();
initial.commit586acc5fe2008-07-26 22:42:52688}
689
Adam Rice425cf122015-01-19 06:18:24690bool HttpNetworkTransaction::UsingHttpProxyWithoutTunnel() const {
Eric Romandbf7441f2020-07-28 07:05:02691 return proxy_info_.is_http_like() &&
Adam Rice425cf122015-01-19 06:18:24692 !(request_->url.SchemeIs("https") || request_->url.SchemeIsWSOrWSS());
693}
694
initial.commit586acc5fe2008-07-26 22:42:52695void HttpNetworkTransaction::DoCallback(int rv) {
[email protected]0b0bf032010-09-21 18:08:50696 DCHECK_NE(rv, ERR_IO_PENDING);
[email protected]49639fa2011-12-20 23:22:41697 DCHECK(!callback_.is_null());
initial.commit586acc5fe2008-07-26 22:42:52698
Douglas Creageref5eecdc2018-11-09 20:50:36699#if BUILDFLAG(ENABLE_REPORTING)
700 // Just before invoking the caller's completion callback, generate a NEL
Lily Chenfec60d92019-01-24 01:16:42701 // report about this network request if the result was an error.
702 GenerateNetworkErrorLoggingReportIfError(rv);
703#endif // BUILDFLAG(ENABLE_REPORTING)
Douglas Creageref5eecdc2018-11-09 20:50:36704
[email protected]96d570e42008-08-05 22:43:04705 // Since Run may result in Read being called, clear user_callback_ up front.
Daniel Chengcac5f4c62019-04-25 22:39:27706 std::move(callback_).Run(rv);
initial.commit586acc5fe2008-07-26 22:42:52707}
708
709void HttpNetworkTransaction::OnIOComplete(int result) {
710 int rv = DoLoop(result);
711 if (rv != ERR_IO_PENDING)
712 DoCallback(rv);
713}
714
715int HttpNetworkTransaction::DoLoop(int result) {
716 DCHECK(next_state_ != STATE_NONE);
717
718 int rv = result;
719 do {
720 State state = next_state_;
721 next_state_ = STATE_NONE;
722 switch (state) {
[email protected]1826a402014-01-08 15:40:48723 case STATE_NOTIFY_BEFORE_CREATE_STREAM:
724 DCHECK_EQ(OK, rv);
725 rv = DoNotifyBeforeCreateStream();
726 break;
[email protected]82918cc2010-08-25 17:24:50727 case STATE_CREATE_STREAM:
728 DCHECK_EQ(OK, rv);
729 rv = DoCreateStream();
730 break;
731 case STATE_CREATE_STREAM_COMPLETE:
732 rv = DoCreateStreamComplete(rv);
733 break;
[email protected]351ab642010-08-05 16:55:31734 case STATE_INIT_STREAM:
735 DCHECK_EQ(OK, rv);
736 rv = DoInitStream();
737 break;
738 case STATE_INIT_STREAM_COMPLETE:
739 rv = DoInitStreamComplete(rv);
740 break;
Aaron Tagliaboschib35cc402021-03-10 22:23:32741 case STATE_CONNECTED_CALLBACK_COMPLETE:
742 rv = DoConnectedCallbackComplete(rv);
743 break;
[email protected]044de0642010-06-17 10:42:15744 case STATE_GENERATE_PROXY_AUTH_TOKEN:
745 DCHECK_EQ(OK, rv);
746 rv = DoGenerateProxyAuthToken();
747 break;
748 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE:
749 rv = DoGenerateProxyAuthTokenComplete(rv);
750 break;
751 case STATE_GENERATE_SERVER_AUTH_TOKEN:
752 DCHECK_EQ(OK, rv);
753 rv = DoGenerateServerAuthToken();
754 break;
755 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE:
756 rv = DoGenerateServerAuthTokenComplete(rv);
757 break;
[email protected]daddea62012-09-19 05:51:13758 case STATE_INIT_REQUEST_BODY:
759 DCHECK_EQ(OK, rv);
760 rv = DoInitRequestBody();
761 break;
762 case STATE_INIT_REQUEST_BODY_COMPLETE:
763 rv = DoInitRequestBodyComplete(rv);
764 break;
[email protected]4875ba12011-03-30 22:31:51765 case STATE_BUILD_REQUEST:
[email protected]725355a2009-03-25 20:42:55766 DCHECK_EQ(OK, rv);
mikecirone8b85c432016-09-08 19:11:00767 net_log_.BeginEvent(NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST);
[email protected]4875ba12011-03-30 22:31:51768 rv = DoBuildRequest();
769 break;
770 case STATE_BUILD_REQUEST_COMPLETE:
771 rv = DoBuildRequestComplete(rv);
772 break;
773 case STATE_SEND_REQUEST:
774 DCHECK_EQ(OK, rv);
[email protected]0877e3d2009-10-17 22:29:57775 rv = DoSendRequest();
initial.commit586acc5fe2008-07-26 22:42:52776 break;
[email protected]0877e3d2009-10-17 22:29:57777 case STATE_SEND_REQUEST_COMPLETE:
778 rv = DoSendRequestComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43779 net_log_.EndEventWithNetErrorCode(
mikecirone8b85c432016-09-08 19:11:00780 NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST, rv);
initial.commit586acc5fe2008-07-26 22:42:52781 break;
782 case STATE_READ_HEADERS:
[email protected]725355a2009-03-25 20:42:55783 DCHECK_EQ(OK, rv);
mikecirone8b85c432016-09-08 19:11:00784 net_log_.BeginEvent(NetLogEventType::HTTP_TRANSACTION_READ_HEADERS);
initial.commit586acc5fe2008-07-26 22:42:52785 rv = DoReadHeaders();
786 break;
787 case STATE_READ_HEADERS_COMPLETE:
788 rv = DoReadHeadersComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43789 net_log_.EndEventWithNetErrorCode(
mikecirone8b85c432016-09-08 19:11:00790 NetLogEventType::HTTP_TRANSACTION_READ_HEADERS, rv);
initial.commit586acc5fe2008-07-26 22:42:52791 break;
792 case STATE_READ_BODY:
[email protected]725355a2009-03-25 20:42:55793 DCHECK_EQ(OK, rv);
mikecirone8b85c432016-09-08 19:11:00794 net_log_.BeginEvent(NetLogEventType::HTTP_TRANSACTION_READ_BODY);
initial.commit586acc5fe2008-07-26 22:42:52795 rv = DoReadBody();
796 break;
797 case STATE_READ_BODY_COMPLETE:
798 rv = DoReadBodyComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43799 net_log_.EndEventWithNetErrorCode(
mikecirone8b85c432016-09-08 19:11:00800 NetLogEventType::HTTP_TRANSACTION_READ_BODY, rv);
initial.commit586acc5fe2008-07-26 22:42:52801 break;
[email protected]2d2697f92009-02-18 21:00:32802 case STATE_DRAIN_BODY_FOR_AUTH_RESTART:
[email protected]725355a2009-03-25 20:42:55803 DCHECK_EQ(OK, rv);
[email protected]9e743cd2010-03-16 07:03:53804 net_log_.BeginEvent(
mikecirone8b85c432016-09-08 19:11:00805 NetLogEventType::HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART);
[email protected]2d2697f92009-02-18 21:00:32806 rv = DoDrainBodyForAuthRestart();
807 break;
808 case STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE:
809 rv = DoDrainBodyForAuthRestartComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43810 net_log_.EndEventWithNetErrorCode(
mikecirone8b85c432016-09-08 19:11:00811 NetLogEventType::HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, rv);
[email protected]2d2697f92009-02-18 21:00:32812 break;
initial.commit586acc5fe2008-07-26 22:42:52813 default:
814 NOTREACHED() << "bad state";
815 rv = ERR_FAILED;
[email protected]96d570e42008-08-05 22:43:04816 break;
initial.commit586acc5fe2008-07-26 22:42:52817 }
818 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
819
820 return rv;
821}
822
[email protected]1826a402014-01-08 15:40:48823int HttpNetworkTransaction::DoNotifyBeforeCreateStream() {
824 next_state_ = STATE_CREATE_STREAM;
825 bool defer = false;
826 if (!before_network_start_callback_.is_null())
Will Cassella61125f92020-07-25 09:11:37827 std::move(before_network_start_callback_).Run(&defer);
[email protected]1826a402014-01-08 15:40:48828 if (!defer)
829 return OK;
830 return ERR_IO_PENDING;
831}
832
[email protected]82918cc2010-08-25 17:24:50833int HttpNetworkTransaction::DoCreateStream() {
ttuttlec0c828492015-05-15 01:25:55834 response_.network_accessed = true;
835
[email protected]82918cc2010-08-25 17:24:50836 next_state_ = STATE_CREATE_STREAM_COMPLETE;
rch2f2991c2017-04-13 19:28:17837 // IP based pooling is only enabled on a retry after 421 Misdirected Request
838 // is received. Alternative Services are also disabled in this case (though
839 // they can also be disabled when retrying after a QUIC error).
840 if (!enable_ip_based_pooling_)
841 DCHECK(!enable_alternative_services_);
[email protected]831e4a32013-11-14 02:14:44842 if (ForWebSocketHandshake()) {
xunjieli96f2a402017-06-05 17:24:27843 stream_request_ =
Bence Béky8cae04e2018-01-15 18:37:06844 session_->http_stream_factory()->RequestWebSocketHandshakeStream(
845 *request_, priority_, server_ssl_config_, proxy_ssl_config_, this,
846 websocket_handshake_stream_base_create_helper_,
847 enable_ip_based_pooling_, enable_alternative_services_, net_log_);
[email protected]831e4a32013-11-14 02:14:44848 } else {
xunjieli96f2a402017-06-05 17:24:27849 stream_request_ = session_->http_stream_factory()->RequestStream(
bnc8016c1f2017-03-31 02:11:29850 *request_, priority_, server_ssl_config_, proxy_ssl_config_, this,
xunjieli96f2a402017-06-05 17:24:27851 enable_ip_based_pooling_, enable_alternative_services_, net_log_);
[email protected]831e4a32013-11-14 02:14:44852 }
[email protected]26816882010-10-14 18:03:09853 DCHECK(stream_request_.get());
[email protected]8e6441ca2010-08-19 05:56:38854 return ERR_IO_PENDING;
[email protected]351ab642010-08-05 16:55:31855}
856
[email protected]82918cc2010-08-25 17:24:50857int HttpNetworkTransaction::DoCreateStreamComplete(int result) {
Eric Roman96c5b292019-04-23 18:04:59858 CopyConnectionAttemptsFromStreamRequest();
[email protected]394816e92010-08-03 07:38:59859 if (result == OK) {
[email protected]82918cc2010-08-25 17:24:50860 next_state_ = STATE_INIT_STREAM;
[email protected]8e6441ca2010-08-19 05:56:38861 DCHECK(stream_.get());
bncfacdd852015-01-09 19:22:54862 } else if (result == ERR_HTTP_1_1_REQUIRED ||
863 result == ERR_PROXY_HTTP_1_1_REQUIRED) {
864 return HandleHttp11Required(result);
[email protected]394816e92010-08-03 07:38:59865 }
866
David Benjamin76a40ad2018-02-24 22:22:08867 // Handle possible client certificate errors that may have occurred if the
868 // stream used SSL for one or more of the layers.
869 result = HandleSSLClientAuthError(result);
[email protected]bd0b6772011-01-11 19:59:30870
[email protected]8e6441ca2010-08-19 05:56:38871 // At this point we are done with the stream_request_.
[email protected]26816882010-10-14 18:03:09872 stream_request_.reset();
[email protected]8e6441ca2010-08-19 05:56:38873 return result;
[email protected]394816e92010-08-03 07:38:59874}
875
[email protected]82918cc2010-08-25 17:24:50876int HttpNetworkTransaction::DoInitStream() {
877 DCHECK(stream_.get());
878 next_state_ = STATE_INIT_STREAM_COMPLETE;
ttuttled9dbc652015-09-29 20:00:59879
880 stream_->GetRemoteEndpoint(&remote_endpoint_);
881
Steven Valdezb4ff0412018-01-18 22:39:27882 return stream_->InitializeStream(request_, can_send_early_data_, priority_,
883 net_log_, io_callback_);
[email protected]82918cc2010-08-25 17:24:50884}
885
886int HttpNetworkTransaction::DoInitStreamComplete(int result) {
Titouan Rigoudy78af7da2020-07-07 14:30:12887 if (result != OK) {
[email protected]82918cc2010-08-25 17:24:50888 if (result < 0)
[email protected]044dcc52010-09-17 15:44:26889 result = HandleIOError(result);
890
891 // The stream initialization failed, so this stream will never be useful.
sclittlefb249892015-09-10 21:33:22892 if (stream_) {
893 total_received_bytes_ += stream_->GetTotalReceivedBytes();
894 total_sent_bytes_ += stream_->GetTotalSentBytes();
895 }
zhongyica364fbb2015-12-12 03:39:12896 CacheNetErrorDetailsAndResetStream();
Titouan Rigoudy78af7da2020-07-07 14:30:12897
898 return result;
[email protected]82918cc2010-08-25 17:24:50899 }
900
Aaron Tagliaboschib35cc402021-03-10 22:23:32901 next_state_ = STATE_CONNECTED_CALLBACK_COMPLETE;
902
Titouan Rigoudy78af7da2020-07-07 14:30:12903 // Fire off notification that we have successfully connected.
904 if (!connected_callback_.is_null()) {
Titouan Rigoudyba507a882020-07-31 12:15:15905 TransportType type = TransportType::kDirect;
906 if (!proxy_info_.is_direct()) {
907 type = TransportType::kProxied;
908 }
Aaron Tagliaboschib35cc402021-03-10 22:23:32909 result = connected_callback_.Run(
Aaron Tagliaboschi603540d22021-04-05 00:37:14910 TransportInfo(type, remote_endpoint_,
911 std::string(stream_->GetAcceptChViaAlps())),
Aaron Tagliaboschib35cc402021-03-10 22:23:32912 base::BindOnce(&HttpNetworkTransaction::ResumeAfterConnected,
913 base::Unretained(this)));
Titouan Rigoudy78af7da2020-07-07 14:30:12914 }
915
Aaron Tagliaboschib35cc402021-03-10 22:23:32916 return result;
917}
918
919int HttpNetworkTransaction::DoConnectedCallbackComplete(int result) {
Titouan Rigoudyc6766812022-04-01 13:29:56920 if (result != OK) {
921 if (stream_) {
922 stream_->Close(/*not_reusable=*/false);
923 }
924
925 // Stop the state machine here if the call failed.
926 return result;
Titouan Rigoudy78af7da2020-07-07 14:30:12927 }
Titouan Rigoudyc6766812022-04-01 13:29:56928
929 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN;
930 return OK;
[email protected]82918cc2010-08-25 17:24:50931}
932
[email protected]044de0642010-06-17 10:42:15933int HttpNetworkTransaction::DoGenerateProxyAuthToken() {
934 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE;
935 if (!ShouldApplyProxyAuth())
936 return OK;
[email protected]394816e92010-08-03 07:38:59937 HttpAuth::Target target = HttpAuth::AUTH_PROXY;
938 if (!auth_controllers_[target].get())
Matt Menkebe090422019-10-18 20:25:26939 auth_controllers_[target] = base::MakeRefCounted<HttpAuthController>(
940 target, AuthURL(target), request_->network_isolation_key,
941 session_->http_auth_cache(), session_->http_auth_handler_factory(),
Rohit Agarwal2653f472019-11-12 19:39:27942 session_->host_resolver());
[email protected]394816e92010-08-03 07:38:59943 return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
[email protected]49639fa2011-12-20 23:22:41944 io_callback_,
[email protected]394816e92010-08-03 07:38:59945 net_log_);
[email protected]044de0642010-06-17 10:42:15946}
947
948int HttpNetworkTransaction::DoGenerateProxyAuthTokenComplete(int rv) {
949 DCHECK_NE(ERR_IO_PENDING, rv);
950 if (rv == OK)
951 next_state_ = STATE_GENERATE_SERVER_AUTH_TOKEN;
952 return rv;
953}
954
955int HttpNetworkTransaction::DoGenerateServerAuthToken() {
956 next_state_ = STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE;
[email protected]394816e92010-08-03 07:38:59957 HttpAuth::Target target = HttpAuth::AUTH_SERVER;
[email protected]2217aa22013-10-11 03:03:54958 if (!auth_controllers_[target].get()) {
Matt Menkebe090422019-10-18 20:25:26959 auth_controllers_[target] = base::MakeRefCounted<HttpAuthController>(
960 target, AuthURL(target), request_->network_isolation_key,
961 session_->http_auth_cache(), session_->http_auth_handler_factory(),
Rohit Agarwal2653f472019-11-12 19:39:27962 session_->host_resolver());
[email protected]2217aa22013-10-11 03:03:54963 if (request_->load_flags & LOAD_DO_NOT_USE_EMBEDDED_IDENTITY)
964 auth_controllers_[target]->DisableEmbeddedIdentity();
965 }
[email protected]044de0642010-06-17 10:42:15966 if (!ShouldApplyServerAuth())
967 return OK;
[email protected]394816e92010-08-03 07:38:59968 return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
[email protected]49639fa2011-12-20 23:22:41969 io_callback_,
[email protected]394816e92010-08-03 07:38:59970 net_log_);
[email protected]044de0642010-06-17 10:42:15971}
972
973int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) {
974 DCHECK_NE(ERR_IO_PENDING, rv);
975 if (rv == OK)
nharperd6e65822016-03-30 23:05:48976 next_state_ = STATE_INIT_REQUEST_BODY;
nharperb7441ef2016-01-25 23:54:14977 return rv;
978}
979
980int HttpNetworkTransaction::BuildRequestHeaders(
Adam Rice425cf122015-01-19 06:18:24981 bool using_http_proxy_without_tunnel) {
[email protected]2979a492011-04-06 00:29:14982 request_headers_.SetHeader(HttpRequestHeaders::kHost,
983 GetHostAndOptionalPort(request_->url));
984
985 // For compat with HTTP/1.0 servers and proxies:
Adam Rice425cf122015-01-19 06:18:24986 if (using_http_proxy_without_tunnel) {
[email protected]2979a492011-04-06 00:29:14987 request_headers_.SetHeader(HttpRequestHeaders::kProxyConnection,
988 "keep-alive");
989 } else {
990 request_headers_.SetHeader(HttpRequestHeaders::kConnection, "keep-alive");
991 }
992
[email protected]2979a492011-04-06 00:29:14993 // Add a content length header?
[email protected]bf3eb002012-11-15 05:50:11994 if (request_->upload_data_stream) {
995 if (request_->upload_data_stream->is_chunked()) {
[email protected]2979a492011-04-06 00:29:14996 request_headers_.SetHeader(
997 HttpRequestHeaders::kTransferEncoding, "chunked");
998 } else {
999 request_headers_.SetHeader(
1000 HttpRequestHeaders::kContentLength,
Daniel Cheng3d199b12017-12-12 03:51:091001 base::NumberToString(request_->upload_data_stream->size()));
[email protected]2979a492011-04-06 00:29:141002 }
csharrisonf473dd192015-08-18 13:54:131003 } else if (request_->method == "POST" || request_->method == "PUT") {
[email protected]2979a492011-04-06 00:29:141004 // An empty POST/PUT request still needs a content length. As for HEAD,
1005 // IE and Safari also add a content length header. Presumably it is to
1006 // support sending a HEAD request to an URL that only expects to be sent a
1007 // POST or some other method that normally would have a message body.
csharrisonf473dd192015-08-18 13:54:131008 // Firefox (40.0) does not send the header, and RFC 7230 & 7231
1009 // specify that it should not be sent due to undefined behavior.
[email protected]2979a492011-04-06 00:29:141010 request_headers_.SetHeader(HttpRequestHeaders::kContentLength, "0");
1011 }
1012
1013 // Honor load flags that impact proxy caches.
1014 if (request_->load_flags & LOAD_BYPASS_CACHE) {
1015 request_headers_.SetHeader(HttpRequestHeaders::kPragma, "no-cache");
1016 request_headers_.SetHeader(HttpRequestHeaders::kCacheControl, "no-cache");
1017 } else if (request_->load_flags & LOAD_VALIDATE_CACHE) {
1018 request_headers_.SetHeader(HttpRequestHeaders::kCacheControl, "max-age=0");
1019 }
1020
1021 if (ShouldApplyProxyAuth() && HaveAuth(HttpAuth::AUTH_PROXY))
1022 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader(
1023 &request_headers_);
1024 if (ShouldApplyServerAuth() && HaveAuth(HttpAuth::AUTH_SERVER))
1025 auth_controllers_[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader(
1026 &request_headers_);
1027
[email protected]c10450102011-06-27 09:06:161028 request_headers_.MergeFrom(request_->extra_headers);
[email protected]1252d42f2014-07-01 21:20:201029
[email protected]173f8e22013-04-10 04:18:201030 response_.did_use_http_auth =
1031 request_headers_.HasHeader(HttpRequestHeaders::kAuthorization) ||
1032 request_headers_.HasHeader(HttpRequestHeaders::kProxyAuthorization);
nharperb7441ef2016-01-25 23:54:141033 return OK;
1034}
1035
[email protected]daddea62012-09-19 05:51:131036int HttpNetworkTransaction::DoInitRequestBody() {
1037 next_state_ = STATE_INIT_REQUEST_BODY_COMPLETE;
[email protected]daddea62012-09-19 05:51:131038 int rv = OK;
[email protected]bf3eb002012-11-15 05:50:111039 if (request_->upload_data_stream)
Matt Menkecc1d3a902018-02-05 18:27:331040 rv = request_->upload_data_stream->Init(
1041 base::BindOnce(&HttpNetworkTransaction::OnIOComplete,
1042 base::Unretained(this)),
1043 net_log_);
[email protected]daddea62012-09-19 05:51:131044 return rv;
1045}
[email protected]4875ba12011-03-30 22:31:511046
[email protected]daddea62012-09-19 05:51:131047int HttpNetworkTransaction::DoInitRequestBodyComplete(int result) {
1048 if (result == OK)
1049 next_state_ = STATE_BUILD_REQUEST;
[email protected]daddea62012-09-19 05:51:131050 return result;
1051}
1052
1053int HttpNetworkTransaction::DoBuildRequest() {
1054 next_state_ = STATE_BUILD_REQUEST_COMPLETE;
[email protected]4875ba12011-03-30 22:31:511055 headers_valid_ = false;
1056
1057 // This is constructed lazily (instead of within our Start method), so that
1058 // we have proxy info available.
1059 if (request_headers_.IsEmpty()) {
Adam Rice425cf122015-01-19 06:18:241060 bool using_http_proxy_without_tunnel = UsingHttpProxyWithoutTunnel();
nharperb7441ef2016-01-25 23:54:141061 return BuildRequestHeaders(using_http_proxy_without_tunnel);
[email protected]4875ba12011-03-30 22:31:511062 }
1063
[email protected]4875ba12011-03-30 22:31:511064 return OK;
1065}
1066
1067int HttpNetworkTransaction::DoBuildRequestComplete(int result) {
[email protected]9f489d72011-04-04 23:29:241068 if (result == OK)
1069 next_state_ = STATE_SEND_REQUEST;
[email protected]4875ba12011-03-30 22:31:511070 return result;
1071}
1072
[email protected]0877e3d2009-10-17 22:29:571073int HttpNetworkTransaction::DoSendRequest() {
[email protected]58e32bb2013-01-21 18:23:251074 send_start_time_ = base::TimeTicks::Now();
[email protected]0877e3d2009-10-17 22:29:571075 next_state_ = STATE_SEND_REQUEST_COMPLETE;
1076
Yu Suba2a1d72020-12-04 02:14:411077 stream_->SetRequestIdempotency(request_->idempotency);
[email protected]bf3eb002012-11-15 05:50:111078 return stream_->SendRequest(request_headers_, &response_, io_callback_);
initial.commit586acc5fe2008-07-26 22:42:521079}
1080
[email protected]0877e3d2009-10-17 22:29:571081int HttpNetworkTransaction::DoSendRequestComplete(int result) {
[email protected]58e32bb2013-01-21 18:23:251082 send_end_time_ = base::TimeTicks::Now();
bncaa171332016-07-20 14:47:361083
1084 if (result == ERR_HTTP_1_1_REQUIRED ||
1085 result == ERR_PROXY_HTTP_1_1_REQUIRED) {
1086 return HandleHttp11Required(result);
1087 }
1088
initial.commit586acc5fe2008-07-26 22:42:521089 if (result < 0)
1090 return HandleIOError(result);
[email protected]0877e3d2009-10-17 22:29:571091 next_state_ = STATE_READ_HEADERS;
initial.commit586acc5fe2008-07-26 22:42:521092 return OK;
1093}
1094
1095int HttpNetworkTransaction::DoReadHeaders() {
1096 next_state_ = STATE_READ_HEADERS_COMPLETE;
[email protected]49639fa2011-12-20 23:22:411097 return stream_->ReadResponseHeaders(io_callback_);
initial.commit586acc5fe2008-07-26 22:42:521098}
1099
1100int HttpNetworkTransaction::DoReadHeadersComplete(int result) {
David Benjamin38c55d32022-01-10 18:59:101101 // We can get a ERR_SSL_CLIENT_AUTH_CERT_NEEDED here due to SSL renegotiation.
1102 // Server certificate errors are impossible. Rather than reverify the new
1103 // server certificate, BoringSSL forbids server certificates from changing.
1104 DCHECK(!IsCertificateError(result));
1105 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
[email protected]8e6441ca2010-08-19 05:56:381106 DCHECK(stream_.get());
Adam Ricecb76ac62015-02-20 05:33:251107 DCHECK(IsSecureRequest());
David Benjamin1c4b6d012019-07-08 17:12:571108 response_.cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>();
[email protected]90499482013-06-01 00:39:501109 stream_->GetSSLCertRequestInfo(response_.cert_request_info.get());
David Benjaminbac8dff2019-08-07 01:30:411110 total_received_bytes_ += stream_->GetTotalReceivedBytes();
1111 total_sent_bytes_ += stream_->GetTotalSentBytes();
1112 stream_->Close(true);
1113 CacheNetErrorDetailsAndResetStream();
[email protected]2181ea002009-06-09 01:37:271114 }
1115
bncfacdd852015-01-09 19:22:541116 if (result == ERR_HTTP_1_1_REQUIRED ||
1117 result == ERR_PROXY_HTTP_1_1_REQUIRED) {
1118 return HandleHttp11Required(result);
1119 }
1120
[email protected]c871864d72014-03-13 19:56:191121 // ERR_CONNECTION_CLOSED is treated differently at this point; if partial
1122 // response headers were received, we do the best we can to make sense of it
1123 // and send it back up the stack.
1124 //
1125 // TODO(davidben): Consider moving this to HttpBasicStream, It's a little
1126 // bizarre for SPDY. Assuming this logic is useful at all.
1127 // TODO(davidben): Bubble the error code up so we do not cache?
1128 if (result == ERR_CONNECTION_CLOSED && response_.headers.get())
1129 result = OK;
1130
1131 if (result < 0)
1132 return HandleIOError(result);
1133
[email protected]90499482013-06-01 00:39:501134 DCHECK(response_.headers.get());
initial.commit586acc5fe2008-07-26 22:42:521135
Kenichi Ishibashi74155532021-03-13 01:38:061136 // Check for a 103 Early Hints response.
1137 if (response_.headers->response_code() == HTTP_EARLY_HINTS) {
1138 NetLogResponseHeaders(
1139 net_log_,
1140 NetLogEventType::HTTP_TRANSACTION_READ_EARLY_HINTS_RESPONSE_HEADERS,
1141 response_.headers.get());
1142
1143 // Early Hints does not make sense for a WebSocket handshake.
1144 if (ForWebSocketHandshake())
1145 return ERR_FAILED;
1146
1147 // TODO(crbug.com/671310): Validate headers? It seems that
1148 // "Content-Encoding" etc should not appear.
1149
1150 if (early_response_headers_callback_)
1151 early_response_headers_callback_.Run(std::move(response_.headers));
1152
1153 response_.headers =
1154 base::MakeRefCounted<HttpResponseHeaders>(std::string());
1155 next_state_ = STATE_READ_HEADERS;
1156 return OK;
1157 }
1158
Matt Menke48f5f2d02021-02-11 18:54:261159 if (!ContentEncodingsValid())
eustasc7d27da2017-04-06 10:33:201160 return ERR_CONTENT_DECODING_FAILED;
1161
[email protected]d58ceea82014-06-04 10:55:541162 // On a 408 response from the server ("Request Timeout") on a stale socket,
David Schinazif832cb82019-11-08 22:25:271163 // retry the request for HTTP/1.1 but not HTTP/2 or QUIC because those
1164 // multiplex requests and have no need for 408.
Matt Menke48f5f2d02021-02-11 18:54:261165 if (response_.headers->response_code() == HTTP_REQUEST_TIMEOUT &&
David Schinazif832cb82019-11-08 22:25:271166 HttpResponseInfo::ConnectionInfoToCoarse(response_.connection_info) ==
1167 HttpResponseInfo::CONNECTION_INFO_COARSE_HTTP1 &&
[email protected]d58ceea82014-06-04 10:55:541168 stream_->IsConnectionReused()) {
Lily Chenfec60d92019-01-24 01:16:421169#if BUILDFLAG(ENABLE_REPORTING)
1170 GenerateNetworkErrorLoggingReport(OK);
1171#endif // BUILDFLAG(ENABLE_REPORTING)
[email protected]d58ceea82014-06-04 10:55:541172 net_log_.AddEventWithNetErrorCode(
mikecirone8b85c432016-09-08 19:11:001173 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR,
[email protected]d58ceea82014-06-04 10:55:541174 response_.headers->response_code());
1175 // This will close the socket - it would be weird to try and reuse it, even
1176 // if the server doesn't actually close it.
1177 ResetConnectionAndRequestForResend();
1178 return OK;
1179 }
1180
Eric Roman06bd9742019-07-13 15:19:131181 NetLogResponseHeaders(net_log_,
1182 NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
1183 response_.headers.get());
Andrey Kosyakov2e893e62017-08-31 17:00:521184 if (response_headers_callback_)
1185 response_headers_callback_.Run(response_.headers);
[email protected]dbb83db2010-05-11 18:13:391186
bncbe0f6af2015-10-15 17:49:561187 if (response_.headers->GetHttpVersion() < HttpVersion(1, 0)) {
[email protected]0877e3d2009-10-17 22:29:571188 // HTTP/0.9 doesn't support the PUT method, so lack of response headers
1189 // indicates a buggy server. See:
1190 // https://bugzilla.mozilla.org/show_bug.cgi?id=193921
1191 if (request_->method == "PUT")
1192 return ERR_METHOD_NOT_SUPPORTED;
1193 }
[email protected]4ddaf2502008-10-23 18:26:191194
Matt Menke48f5f2d02021-02-11 18:54:261195 if (can_send_early_data_ &&
Steven Valdez58097ec32018-07-16 18:29:041196 response_.headers->response_code() == HTTP_TOO_EARLY) {
1197 return HandleIOError(ERR_EARLY_DATA_REJECTED);
1198 }
1199
[email protected]0877e3d2009-10-17 22:29:571200 // Check for an intermediate 100 Continue response. An origin server is
1201 // allowed to send this response even if we didn't ask for it, so we just
1202 // need to skip over it.
1203 // We treat any other 1xx in this same way (although in practice getting
1204 // a 1xx that isn't a 100 is rare).
[email protected]831e4a32013-11-14 02:14:441205 // Unless this is a WebSocket request, in which case we pass it on up.
1206 if (response_.headers->response_code() / 100 == 1 &&
1207 !ForWebSocketHandshake()) {
[email protected]007b3f82013-04-09 08:46:451208 response_.headers = new HttpResponseHeaders(std::string());
[email protected]0877e3d2009-10-17 22:29:571209 next_state_ = STATE_READ_HEADERS;
1210 return OK;
1211 }
1212
davidbence688ae2017-05-04 15:12:591213 if (response_.headers->response_code() == 421 &&
1214 (enable_ip_based_pooling_ || enable_alternative_services_)) {
Lily Chenfec60d92019-01-24 01:16:421215#if BUILDFLAG(ENABLE_REPORTING)
1216 GenerateNetworkErrorLoggingReport(OK);
1217#endif // BUILDFLAG(ENABLE_REPORTING)
davidbence688ae2017-05-04 15:12:591218 // Retry the request with both IP based pooling and Alternative Services
1219 // disabled.
1220 enable_ip_based_pooling_ = false;
1221 enable_alternative_services_ = false;
1222 net_log_.AddEvent(
1223 NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST);
1224 ResetConnectionAndRequestForResend();
1225 return OK;
bnc8016c1f2017-03-31 02:11:291226 }
1227
bncb26024382016-06-29 02:39:451228 if (IsSecureRequest()) {
asanka5ffd5d72016-03-23 16:20:491229 stream_->GetSSLInfo(&response_.ssl_info);
Bence Béky230ac612017-08-30 19:17:081230 if (response_.ssl_info.is_valid() &&
1231 !IsCertStatusError(response_.ssl_info.cert_status)) {
1232 session_->http_stream_factory()->ProcessAlternativeServices(
Matt Menkeb32ba5122019-09-10 19:17:051233 session_, network_isolation_key_, response_.headers.get(),
Bence Béky230ac612017-08-30 19:17:081234 url::SchemeHostPort(request_->url));
1235 }
1236 }
asanka5ffd5d72016-03-23 16:20:491237
[email protected]e772db3f2010-07-12 18:11:131238 int rv = HandleAuthChallenge();
[email protected]0877e3d2009-10-17 22:29:571239 if (rv != OK)
1240 return rv;
1241
Douglas Creager3cb042052018-11-06 23:08:521242#if BUILDFLAG(ENABLE_REPORTING)
Ian Clelland4563d4d2021-06-02 20:25:501243 // Note: This just handles the legacy Report-To header, which is still
1244 // required for NEL. The newer Reporting-Endpoints header is processed in
1245 // network::PopulateParsedHeaders().
1246 ProcessReportToHeader();
1247
Lily Chenfec60d92019-01-24 01:16:421248 // Note: Unless there is a pre-existing NEL policy for this origin, any NEL
1249 // reports generated before the NEL header is processed here will just be
1250 // dropped by the NetworkErrorLoggingService.
Douglas Creager3cb042052018-11-06 23:08:521251 ProcessNetworkErrorLoggingHeader();
Lily Chenfec60d92019-01-24 01:16:421252
1253 // Generate NEL report here if we have to report an HTTP error (4xx or 5xx
Lily Chend3930e72019-03-01 19:31:111254 // code), or if the response body will not be read, or on a redirect.
1255 // Note: This will report a success for a redirect even if an error is
1256 // encountered later while draining the body.
Lily Chenfec60d92019-01-24 01:16:421257 int response_code = response_.headers->response_code();
1258 if ((response_code >= 400 && response_code < 600) ||
1259 response_code == HTTP_NO_CONTENT || response_code == HTTP_RESET_CONTENT ||
1260 response_code == HTTP_NOT_MODIFIED || request_->method == "HEAD" ||
Lily Chend3930e72019-03-01 19:31:111261 response_.headers->GetContentLength() == 0 ||
1262 response_.headers->IsRedirect(nullptr /* location */)) {
Lily Chenfec60d92019-01-24 01:16:421263 GenerateNetworkErrorLoggingReport(OK);
1264 }
1265#endif // BUILDFLAG(ENABLE_REPORTING)
Douglas Creager3cb042052018-11-06 23:08:521266
[email protected]0877e3d2009-10-17 22:29:571267 headers_valid_ = true;
Shivani Sharmafdcaefd2017-11-02 00:12:261268
1269 // We have reached the end of Start state machine, set the RequestInfo to
1270 // null.
1271 // RequestInfo is a member of the HttpTransaction's consumer and is useful
1272 // only until the final response headers are received. Clearing it will ensure
1273 // that HttpRequestInfo is only used up until final response headers are
1274 // received. Clearing is allowed so that the transaction can be disassociated
1275 // from its creating consumer in cases where it is shared for writing to the
1276 // cache. It is also safe to set it to null at this point since
1277 // upload_data_stream is also not used in the Read state machine.
1278 if (pending_auth_target_ == HttpAuth::AUTH_NONE)
1279 request_ = nullptr;
1280
[email protected]0877e3d2009-10-17 22:29:571281 return OK;
initial.commit586acc5fe2008-07-26 22:42:521282}
1283
1284int HttpNetworkTransaction::DoReadBody() {
[email protected]90499482013-06-01 00:39:501285 DCHECK(read_buf_.get());
[email protected]6501bc02009-06-25 20:55:131286 DCHECK_GT(read_buf_len_, 0);
Raul Tambre94493c652019-03-11 17:18:351287 DCHECK(stream_ != nullptr);
initial.commit586acc5fe2008-07-26 22:42:521288
1289 next_state_ = STATE_READ_BODY_COMPLETE;
[email protected]90499482013-06-01 00:39:501290 return stream_->ReadResponseBody(
1291 read_buf_.get(), read_buf_len_, io_callback_);
initial.commit586acc5fe2008-07-26 22:42:521292}
1293
1294int HttpNetworkTransaction::DoReadBodyComplete(int result) {
1295 // We are done with the Read call.
[email protected]8e6441ca2010-08-19 05:56:381296 bool done = false;
1297 if (result <= 0) {
1298 DCHECK_NE(ERR_IO_PENDING, result);
initial.commit586acc5fe2008-07-26 22:42:521299 done = true;
[email protected]8e6441ca2010-08-19 05:56:381300 }
[email protected]9492e4a2010-02-24 00:58:461301
mmenkebd84c392015-09-02 14:12:341302 // Clean up connection if we are done.
1303 if (done) {
[email protected]8e6441ca2010-08-19 05:56:381304 // Note: Just because IsResponseBodyComplete is true, we're not
1305 // necessarily "done". We're only "done" when it is the last
1306 // read on this HttpNetworkTransaction, which will be signified
1307 // by a zero-length read.
mmenkebd84c392015-09-02 14:12:341308 // TODO(mbelshe): The keep-alive property is really a property of
[email protected]8e6441ca2010-08-19 05:56:381309 // the stream. No need to compute it here just to pass back
1310 // to the stream's Close function.
mmenkebd84c392015-09-02 14:12:341311 bool keep_alive =
1312 stream_->IsResponseBodyComplete() && stream_->CanReuseConnection();
initial.commit586acc5fe2008-07-26 22:42:521313
[email protected]8e6441ca2010-08-19 05:56:381314 stream_->Close(!keep_alive);
[email protected]e2a915a2010-08-19 07:55:011315 // Note: we don't reset the stream here. We've closed it, but we still
1316 // need it around so that callers can call methods such as
1317 // GetUploadProgress() and have them be meaningful.
1318 // TODO(mbelshe): This means we closed the stream here, and we close it
1319 // again in ~HttpNetworkTransaction. Clean that up.
1320
[email protected]8e6441ca2010-08-19 05:56:381321 // The next Read call will return 0 (EOF).
rch2f2991c2017-04-13 19:28:171322
1323 // This transaction was successful. If it had been retried because of an
1324 // error with an alternative service, mark that alternative service broken.
1325 if (!enable_alternative_services_ &&
1326 retried_alternative_service_.protocol != kProtoUnknown) {
Ryan Hamilton9f532a12019-04-22 22:26:411327 HistogramBrokenAlternateProtocolLocation(
1328 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_NETWORK_TRANSACTION);
rch2f2991c2017-04-13 19:28:171329 session_->http_server_properties()->MarkAlternativeServiceBroken(
Matt Menkeb32ba5122019-09-10 19:17:051330 retried_alternative_service_, network_isolation_key_);
rch2f2991c2017-04-13 19:28:171331 }
Lily Chenfec60d92019-01-24 01:16:421332
1333#if BUILDFLAG(ENABLE_REPORTING)
1334 GenerateNetworkErrorLoggingReport(result);
1335#endif // BUILDFLAG(ENABLE_REPORTING)
initial.commit586acc5fe2008-07-26 22:42:521336 }
1337
1338 // Clear these to avoid leaving around old state.
Raul Tambre94493c652019-03-11 17:18:351339 read_buf_ = nullptr;
initial.commit586acc5fe2008-07-26 22:42:521340 read_buf_len_ = 0;
1341
1342 return result;
1343}
1344
[email protected]2d2697f92009-02-18 21:00:321345int HttpNetworkTransaction::DoDrainBodyForAuthRestart() {
1346 // This method differs from DoReadBody only in the next_state_. So we just
1347 // call DoReadBody and override the next_state_. Perhaps there is a more
1348 // elegant way for these two methods to share code.
1349 int rv = DoReadBody();
1350 DCHECK(next_state_ == STATE_READ_BODY_COMPLETE);
1351 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE;
1352 return rv;
1353}
1354
[email protected]0877e3d2009-10-17 22:29:571355// TODO(wtc): This method and the DoReadBodyComplete method are almost
1356// the same. Figure out a good way for these two methods to share code.
[email protected]2d2697f92009-02-18 21:00:321357int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) {
[email protected]68873ba2009-06-04 21:49:231358 // keep_alive defaults to true because the very reason we're draining the
1359 // response body is to reuse the connection for auth restart.
1360 bool done = false, keep_alive = true;
[email protected]2d2697f92009-02-18 21:00:321361 if (result < 0) {
[email protected]0877e3d2009-10-17 22:29:571362 // Error or closed connection while reading the socket.
Lily Chenfec60d92019-01-24 01:16:421363 // Note: No Network Error Logging report is generated here because a report
1364 // will have already been generated for the original request due to the auth
1365 // challenge, so a second report is not generated for the same request here.
[email protected]2d2697f92009-02-18 21:00:321366 done = true;
[email protected]68873ba2009-06-04 21:49:231367 keep_alive = false;
[email protected]351ab642010-08-05 16:55:311368 } else if (stream_->IsResponseBodyComplete()) {
[email protected]0877e3d2009-10-17 22:29:571369 done = true;
[email protected]2d2697f92009-02-18 21:00:321370 }
1371
1372 if (done) {
1373 DidDrainBodyForAuthRestart(keep_alive);
1374 } else {
1375 // Keep draining.
1376 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART;
1377 }
1378
1379 return OK;
1380}
1381
Douglas Creager3cb042052018-11-06 23:08:521382#if BUILDFLAG(ENABLE_REPORTING)
Douglas Creager134b52e2018-11-09 18:00:141383void HttpNetworkTransaction::ProcessReportToHeader() {
1384 std::string value;
1385 if (!response_.headers->GetNormalizedHeader("Report-To", &value))
1386 return;
1387
Matt Menkef437a87e2020-10-22 23:22:241388 ReportingService* reporting_service = session_->reporting_service();
1389 if (!reporting_service)
Douglas Creager134b52e2018-11-09 18:00:141390 return;
Douglas Creager134b52e2018-11-09 18:00:141391
1392 // Only accept Report-To headers on HTTPS connections that have no
1393 // certificate errors.
Lily Chen9364a4c2020-06-25 16:07:521394 if (!response_.ssl_info.is_valid())
Douglas Creager134b52e2018-11-09 18:00:141395 return;
Lily Chen9364a4c2020-06-25 16:07:521396 if (IsCertStatusError(response_.ssl_info.cert_status))
Douglas Creager134b52e2018-11-09 18:00:141397 return;
Douglas Creager134b52e2018-11-09 18:00:141398
Matt Menkee4399022021-10-21 18:04:421399 reporting_service->ProcessReportToHeader(url::Origin::Create(url_),
Rodney Ding329e4bb2021-03-19 22:21:531400 network_isolation_key_, value);
Douglas Creager134b52e2018-11-09 18:00:141401}
1402
Douglas Creager3cb042052018-11-06 23:08:521403void HttpNetworkTransaction::ProcessNetworkErrorLoggingHeader() {
1404 std::string value;
1405 if (!response_.headers->GetNormalizedHeader(
1406 NetworkErrorLoggingService::kHeaderName, &value)) {
1407 return;
1408 }
1409
Matt Menkef437a87e2020-10-22 23:22:241410 NetworkErrorLoggingService* network_error_logging_service =
Douglas Creager3cb042052018-11-06 23:08:521411 session_->network_error_logging_service();
Matt Menkef437a87e2020-10-22 23:22:241412 if (!network_error_logging_service)
Douglas Creager3cb042052018-11-06 23:08:521413 return;
Douglas Creager3cb042052018-11-06 23:08:521414
Lily Chen90ae93cc2019-02-14 01:15:391415 // Don't accept NEL headers received via a proxy, because the IP address of
1416 // the destination server is not known.
1417 if (response_.was_fetched_via_proxy)
1418 return;
1419
Douglas Creager3cb042052018-11-06 23:08:521420 // Only accept NEL headers on HTTPS connections that have no certificate
1421 // errors.
Lily Chena9e9d6cb2020-06-25 17:34:491422 if (!response_.ssl_info.is_valid() ||
1423 IsCertStatusError(response_.ssl_info.cert_status)) {
Douglas Creager3cb042052018-11-06 23:08:521424 return;
1425 }
1426
Lily Chena9e9d6cb2020-06-25 17:34:491427 if (remote_endpoint_.address().empty())
Douglas Creager3cb042052018-11-06 23:08:521428 return;
Douglas Creager3cb042052018-11-06 23:08:521429
Matt Menkef437a87e2020-10-22 23:22:241430 network_error_logging_service->OnHeader(network_isolation_key_,
1431 url::Origin::Create(url_),
1432 remote_endpoint_.address(), value);
Douglas Creager3cb042052018-11-06 23:08:521433}
Douglas Creageref5eecdc2018-11-09 20:50:361434
Lily Chenfec60d92019-01-24 01:16:421435void HttpNetworkTransaction::GenerateNetworkErrorLoggingReportIfError(int rv) {
1436 if (rv < 0 && rv != ERR_IO_PENDING)
1437 GenerateNetworkErrorLoggingReport(rv);
1438}
1439
Douglas Creageref5eecdc2018-11-09 20:50:361440void HttpNetworkTransaction::GenerateNetworkErrorLoggingReport(int rv) {
Lily Chenfec60d92019-01-24 01:16:421441 // |rv| should be a valid net::Error
1442 DCHECK_NE(rv, ERR_IO_PENDING);
1443 DCHECK_LE(rv, 0);
1444
1445 if (network_error_logging_report_generated_)
1446 return;
1447 network_error_logging_report_generated_ = true;
1448
Douglas Creageref5eecdc2018-11-09 20:50:361449 NetworkErrorLoggingService* service =
1450 session_->network_error_logging_service();
Lily Chend613caa2019-11-25 20:46:331451 if (!service)
Douglas Creageref5eecdc2018-11-09 20:50:361452 return;
Douglas Creageref5eecdc2018-11-09 20:50:361453
Lily Chen90ae93cc2019-02-14 01:15:391454 // Don't report on proxy auth challenges.
1455 if (response_.headers && response_.headers->response_code() ==
1456 HTTP_PROXY_AUTHENTICATION_REQUIRED) {
1457 return;
1458 }
1459
1460 // Don't generate NEL reports if we are behind a proxy, to avoid leaking
1461 // internal network details.
1462 if (response_.was_fetched_via_proxy)
1463 return;
1464
Lily Chen00196ab62018-12-04 19:52:291465 // Ignore errors from non-HTTPS origins.
Lily Chend613caa2019-11-25 20:46:331466 if (!url_.SchemeIsCryptographic())
Lily Chen00196ab62018-12-04 19:52:291467 return;
Douglas Creageref5eecdc2018-11-09 20:50:361468
1469 NetworkErrorLoggingService::RequestDetails details;
1470
Matt Menkef437a87e2020-10-22 23:22:241471 details.network_isolation_key = network_isolation_key_;
Douglas Creageref5eecdc2018-11-09 20:50:361472 details.uri = url_;
1473 if (!request_referrer_.empty())
1474 details.referrer = GURL(request_referrer_);
1475 details.user_agent = request_user_agent_;
Lily Chenfec60d92019-01-24 01:16:421476 if (!remote_endpoint_.address().empty()) {
Douglas Creageref5eecdc2018-11-09 20:50:361477 details.server_ip = remote_endpoint_.address();
Lily Chenfec60d92019-01-24 01:16:421478 } else {
1479 details.server_ip = IPAddress();
1480 }
Douglas Creageref5eecdc2018-11-09 20:50:361481 // HttpResponseHeaders::response_code() returns 0 if response code couldn't
1482 // be parsed, which is also how NEL represents the same.
Lily Chenfec60d92019-01-24 01:16:421483 if (response_.headers) {
Douglas Creageref5eecdc2018-11-09 20:50:361484 details.status_code = response_.headers->response_code();
Lily Chenfec60d92019-01-24 01:16:421485 } else {
Douglas Creageref5eecdc2018-11-09 20:50:361486 details.status_code = 0;
Lily Chenfec60d92019-01-24 01:16:421487 }
Douglas Creageref5eecdc2018-11-09 20:50:361488 // If we got response headers, assume that the connection used HTTP/1.1
1489 // unless ALPN negotiation tells us otherwise (handled below).
Lily Chenfec60d92019-01-24 01:16:421490 if (response_.was_alpn_negotiated) {
Douglas Creageref5eecdc2018-11-09 20:50:361491 details.protocol = response_.alpn_negotiated_protocol;
Lily Chenfec60d92019-01-24 01:16:421492 } else {
Douglas Creageref5eecdc2018-11-09 20:50:361493 details.protocol = "http/1.1";
Douglas Creageref5eecdc2018-11-09 20:50:361494 }
Lily Chenfec60d92019-01-24 01:16:421495 details.method = request_method_;
1496 details.elapsed_time = base::TimeTicks::Now() - start_timeticks_;
Douglas Creageref5eecdc2018-11-09 20:50:361497 details.type = static_cast<Error>(rv);
1498 details.reporting_upload_depth = request_reporting_upload_depth_;
1499
1500 service->OnRequest(std::move(details));
1501}
Lily Chenfec60d92019-01-24 01:16:421502#endif // BUILDFLAG(ENABLE_REPORTING)
Douglas Creager3cb042052018-11-06 23:08:521503
bncfacdd852015-01-09 19:22:541504int HttpNetworkTransaction::HandleHttp11Required(int error) {
1505 DCHECK(error == ERR_HTTP_1_1_REQUIRED ||
1506 error == ERR_PROXY_HTTP_1_1_REQUIRED);
1507
Matt Menke0e3276862019-08-23 00:21:341508 // HttpServerProperties should have been updated, so when the request is sent
1509 // again, it will automatically use HTTP/1.1.
bncfacdd852015-01-09 19:22:541510 ResetConnectionAndRequestForResend();
1511 return OK;
1512}
1513
David Benjamin76a40ad2018-02-24 22:22:081514int HttpNetworkTransaction::HandleSSLClientAuthError(int error) {
David Benjaminbac8dff2019-08-07 01:30:411515 // Client certificate errors may come from either the origin server or the
1516 // proxy.
1517 //
1518 // Origin errors are handled here, while most proxy errors are handled in the
David Benjamin587def42021-03-30 15:38:441519 // HttpStreamFactory and below, while handshaking with the proxy. However, in
1520 // TLS 1.2 with False Start, or TLS 1.3, client certificate errors are
1521 // reported immediately after the handshake. The error will then surface out
1522 // of the first Read() rather than Connect().
1523 //
1524 // If the request is tunneled (i.e. the origin is HTTPS), this first Read()
1525 // occurs while establishing the tunnel and HttpStreamFactory handles the
1526 // proxy error. However, if the request is not tunneled (i.e. the origin is
1527 // HTTP), this first Read() happens late and is ultimately surfaced out of
1528 // DoReadHeadersComplete(). This method will then be responsible for both
1529 // origin and proxy errors.
David Benjamin3b94b0f2019-04-25 23:07:521530 //
1531 // See https://crbug.com/828965.
David Benjaminbac8dff2019-08-07 01:30:411532 bool is_server = !UsingHttpProxyWithoutTunnel();
1533 HostPortPair host_port_pair =
1534 is_server ? HostPortPair::FromURL(request_->url)
1535 : proxy_info_.proxy_server().host_port_pair();
David Benjamin3b94b0f2019-04-25 23:07:521536
David Benjaminbac8dff2019-08-07 01:30:411537 if (error == ERR_SSL_PROTOCOL_ERROR || IsClientCertificateError(error)) {
Eric Romandbf7441f2020-07-28 07:05:021538 DCHECK((is_server && IsSecureRequest()) ||
1539 proxy_info_.is_secure_http_like());
David Benjaminbac8dff2019-08-07 01:30:411540 if (session_->ssl_client_context()->ClearClientCertificate(
1541 host_port_pair)) {
1542 // The private key handle may have gone stale due to, e.g., the user
1543 // unplugging their smartcard. Operating systems do not provide reliable
1544 // notifications for this, so if the signature failed and the user was
1545 // not already prompted for certificate on this request, retry to ask
1546 // the user for a new one.
1547 //
1548 // TODO(davidben): There is no corresponding feature for proxy client
1549 // certificates. Ideally this would live at a lower level, common to both,
1550 // but |configured_client_cert_for_server_| is not accessible below the
1551 // socket pools.
1552 if (is_server && error == ERR_SSL_CLIENT_AUTH_SIGNATURE_FAILED &&
1553 !configured_client_cert_for_server_ && !HasExceededMaxRetries()) {
1554 retry_attempts_++;
1555 net_log_.AddEventWithNetErrorCode(
1556 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
1557 ResetConnectionAndRequestForResend();
1558 return OK;
1559 }
David Benjamin76a40ad2018-02-24 22:22:081560 }
1561 }
initial.commit586acc5fe2008-07-26 22:42:521562 return error;
1563}
1564
[email protected]bd0b6772011-01-11 19:59:301565// This method determines whether it is safe to resend the request after an
1566// IO error. It can only be called in response to request header or body
1567// write errors or response header read errors. It should not be used in
1568// other cases, such as a Connect error.
1569int HttpNetworkTransaction::HandleIOError(int error) {
[email protected]384cc73a2013-12-08 22:41:031570 // Because the peer may request renegotiation with client authentication at
1571 // any time, check and handle client authentication errors.
David Benjamin76a40ad2018-02-24 22:22:081572 error = HandleSSLClientAuthError(error);
[email protected]bd0b6772011-01-11 19:59:301573
Lily Chenfec60d92019-01-24 01:16:421574#if BUILDFLAG(ENABLE_REPORTING)
1575 GenerateNetworkErrorLoggingReportIfError(error);
1576#endif // BUILDFLAG(ENABLE_REPORTING)
1577
[email protected]bd0b6772011-01-11 19:59:301578 switch (error) {
1579 // If we try to reuse a connection that the server is in the process of
1580 // closing, we may end up successfully writing out our request (or a
1581 // portion of our request) only to find a connection error when we try to
1582 // read from (or finish writing to) the socket.
1583 case ERR_CONNECTION_RESET:
1584 case ERR_CONNECTION_CLOSED:
1585 case ERR_CONNECTION_ABORTED:
[email protected]202965992011-12-07 23:04:511586 // There can be a race between the socket pool checking checking whether a
1587 // socket is still connected, receiving the FIN, and sending/reading data
1588 // on a reused socket. If we receive the FIN between the connectedness
1589 // check and writing/reading from the socket, we may first learn the socket
1590 // is disconnected when we get a ERR_SOCKET_NOT_CONNECTED. This will most
1591 // likely happen when trying to retrieve its IP address.
1592 // See http://crbug.com/105824 for more details.
1593 case ERR_SOCKET_NOT_CONNECTED:
[email protected]a34f61ee2014-03-18 20:59:491594 // If a socket is closed on its initial request, HttpStreamParser returns
1595 // ERR_EMPTY_RESPONSE. This may still be close/reuse race if the socket was
1596 // preconnected but failed to be used before the server timed it out.
1597 case ERR_EMPTY_RESPONSE:
1598 if (ShouldResendRequest()) {
[email protected]b6754252012-06-13 23:14:381599 net_log_.AddEventWithNetErrorCode(
mikecirone8b85c432016-09-08 19:11:001600 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
[email protected]bd0b6772011-01-11 19:59:301601 ResetConnectionAndRequestForResend();
1602 error = OK;
1603 }
1604 break;
Steven Valdez58097ec32018-07-16 18:29:041605 case ERR_EARLY_DATA_REJECTED:
1606 case ERR_WRONG_VERSION_ON_EARLY_DATA:
1607 net_log_.AddEventWithNetErrorCode(
1608 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
1609 // Disable early data on the SSLConfig on a reset.
1610 can_send_early_data_ = false;
1611 ResetConnectionAndRequestForResend();
1612 error = OK;
1613 break;
Bence Békyd0d69502019-06-25 19:47:181614 case ERR_HTTP2_PING_FAILED:
1615 case ERR_HTTP2_SERVER_REFUSED_STREAM:
1616 case ERR_HTTP2_PUSHED_STREAM_NOT_AVAILABLE:
1617 case ERR_HTTP2_CLAIMED_PUSHED_STREAM_RESET_BY_SERVER:
1618 case ERR_HTTP2_PUSHED_RESPONSE_DOES_NOT_MATCH:
[email protected]4d283b32013-10-17 12:57:271619 case ERR_QUIC_HANDSHAKE_FAILED:
Bence Béky2ee18922020-09-25 12:11:321620 case ERR_QUIC_GOAWAY_REQUEST_CAN_BE_RETRIED:
Biljith Jayan45a41722017-08-16 18:43:141621 if (HasExceededMaxRetries())
1622 break;
[email protected]b6754252012-06-13 23:14:381623 net_log_.AddEventWithNetErrorCode(
mikecirone8b85c432016-09-08 19:11:001624 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
Biljith Jayan45a41722017-08-16 18:43:141625 retry_attempts_++;
[email protected]721c0ce2011-10-13 02:41:001626 ResetConnectionAndRequestForResend();
1627 error = OK;
1628 break;
rch2f2991c2017-04-13 19:28:171629 case ERR_QUIC_PROTOCOL_ERROR:
1630 if (GetResponseHeaders() != nullptr ||
1631 !stream_->GetAlternativeService(&retried_alternative_service_)) {
1632 // If the response headers have already been recieved and passed up
1633 // then the request can not be retried. Also, if there was no
1634 // alternative service used for this request, then there is no
1635 // alternative service to be disabled.
1636 break;
1637 }
Biljith Jayan45a41722017-08-16 18:43:141638 if (HasExceededMaxRetries())
1639 break;
rch2f2991c2017-04-13 19:28:171640 if (session_->http_server_properties()->IsAlternativeServiceBroken(
Matt Menkeb32ba5122019-09-10 19:17:051641 retried_alternative_service_, network_isolation_key_)) {
rch2f2991c2017-04-13 19:28:171642 // If the alternative service was marked as broken while the request
1643 // was in flight, retry the request which will not use the broken
1644 // alternative service.
1645 net_log_.AddEventWithNetErrorCode(
1646 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
Biljith Jayan45a41722017-08-16 18:43:141647 retry_attempts_++;
rch2f2991c2017-04-13 19:28:171648 ResetConnectionAndRequestForResend();
1649 error = OK;
Victor Vasilieva1e66d72019-12-05 17:55:381650 } else if (session_->context()
1651 .quic_context->params()
1652 ->retry_without_alt_svc_on_quic_errors) {
rch2f2991c2017-04-13 19:28:171653 // Disable alternative services for this request and retry it. If the
1654 // retry succeeds, then the alternative service will be marked as
1655 // broken then.
1656 enable_alternative_services_ = false;
rch514a44a82017-04-13 04:46:361657 net_log_.AddEventWithNetErrorCode(
1658 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
Biljith Jayan45a41722017-08-16 18:43:141659 retry_attempts_++;
rch514a44a82017-04-13 04:46:361660 ResetConnectionAndRequestForResend();
1661 error = OK;
1662 }
1663 break;
[email protected]bd0b6772011-01-11 19:59:301664 }
1665 return error;
1666}
1667
[email protected]c3b35c22008-09-27 03:19:421668void HttpNetworkTransaction::ResetStateForRestart() {
[email protected]697ef4c2010-10-14 16:38:581669 ResetStateForAuthRestart();
sclittlefb249892015-09-10 21:33:221670 if (stream_) {
[email protected]b8015c42013-12-24 15:18:191671 total_received_bytes_ += stream_->GetTotalReceivedBytes();
sclittlefb249892015-09-10 21:33:221672 total_sent_bytes_ += stream_->GetTotalSentBytes();
1673 }
zhongyica364fbb2015-12-12 03:39:121674 CacheNetErrorDetailsAndResetStream();
[email protected]697ef4c2010-10-14 16:38:581675}
1676
1677void HttpNetworkTransaction::ResetStateForAuthRestart() {
[email protected]58e32bb2013-01-21 18:23:251678 send_start_time_ = base::TimeTicks();
1679 send_end_time_ = base::TimeTicks();
[email protected]58e32bb2013-01-21 18:23:251680
[email protected]0757e7702009-03-27 04:00:221681 pending_auth_target_ = HttpAuth::AUTH_NONE;
Raul Tambre94493c652019-03-11 17:18:351682 read_buf_ = nullptr;
[email protected]c3b35c22008-09-27 03:19:421683 read_buf_len_ = 0;
[email protected]0877e3d2009-10-17 22:29:571684 headers_valid_ = false;
[email protected]b94f92d2010-10-27 16:45:201685 request_headers_.Clear();
[email protected]a7e41312009-12-16 23:18:141686 response_ = HttpResponseInfo();
Wojciech Dzierżanowski758b4fb2021-04-19 23:26:591687 SetProxyInfoInReponse(proxy_info_, &response_);
[email protected]8e6441ca2010-08-19 05:56:381688 establishing_tunnel_ = false;
ttuttled9dbc652015-09-29 20:00:591689 remote_endpoint_ = IPEndPoint();
zhongyica364fbb2015-12-12 03:39:121690 net_error_details_.quic_broken = false;
Ryan Hamilton8d9ee76e2018-05-29 23:52:521691 net_error_details_.quic_connection_error = quic::QUIC_NO_ERROR;
Lily Chenfec60d92019-01-24 01:16:421692#if BUILDFLAG(ENABLE_REPORTING)
1693 network_error_logging_report_generated_ = false;
1694 start_timeticks_ = base::TimeTicks::Now();
1695#endif // BUILDFLAG(ENABLE_REPORTING)
zhongyica364fbb2015-12-12 03:39:121696}
1697
1698void HttpNetworkTransaction::CacheNetErrorDetailsAndResetStream() {
1699 if (stream_)
1700 stream_->PopulateNetErrorDetails(&net_error_details_);
1701 stream_.reset();
[email protected]0877e3d2009-10-17 22:29:571702}
1703
1704HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const {
[email protected]90499482013-06-01 00:39:501705 return response_.headers.get();
[email protected]c3b35c22008-09-27 03:19:421706}
1707
[email protected]a34f61ee2014-03-18 20:59:491708bool HttpNetworkTransaction::ShouldResendRequest() const {
[email protected]8e6441ca2010-08-19 05:56:381709 bool connection_is_proven = stream_->IsConnectionReused();
Raul Tambre94493c652019-03-11 17:18:351710 bool has_received_headers = GetResponseHeaders() != nullptr;
[email protected]58cebf8f2010-07-31 19:20:161711
[email protected]2a5c76b2008-09-25 22:15:161712 // NOTE: we resend a request only if we reused a keep-alive connection.
1713 // This automatically prevents an infinite resend loop because we'll run
1714 // out of the cached keep-alive connections eventually.
[email protected]8e6441ca2010-08-19 05:56:381715 if (connection_is_proven && !has_received_headers)
1716 return true;
1717 return false;
[email protected]1c773ea12009-04-28 19:58:421718}
1719
Biljith Jayan45a41722017-08-16 18:43:141720bool HttpNetworkTransaction::HasExceededMaxRetries() const {
1721 return (retry_attempts_ >= kMaxRetryAttempts);
1722}
1723
David Benjamin83ddfb32018-03-30 01:07:521724bool HttpNetworkTransaction::CheckMaxRestarts() {
1725 num_restarts_++;
1726 return num_restarts_ < kMaxRestarts;
1727}
1728
[email protected]1c773ea12009-04-28 19:58:421729void HttpNetworkTransaction::ResetConnectionAndRequestForResend() {
[email protected]8e6441ca2010-08-19 05:56:381730 if (stream_.get()) {
1731 stream_->Close(true);
zhongyica364fbb2015-12-12 03:39:121732 CacheNetErrorDetailsAndResetStream();
[email protected]58cebf8f2010-07-31 19:20:161733 }
1734
[email protected]0877e3d2009-10-17 22:29:571735 // We need to clear request_headers_ because it contains the real request
1736 // headers, but we may need to resend the CONNECT request first to recreate
1737 // the SSL tunnel.
[email protected]b94f92d2010-10-27 16:45:201738 request_headers_.Clear();
[email protected]82918cc2010-08-25 17:24:501739 next_state_ = STATE_CREATE_STREAM; // Resend the request.
Lily Chenfec60d92019-01-24 01:16:421740
1741#if BUILDFLAG(ENABLE_REPORTING)
1742 // Reset for new request.
1743 network_error_logging_report_generated_ = false;
1744 start_timeticks_ = base::TimeTicks::Now();
1745#endif // BUILDFLAG(ENABLE_REPORTING)
Wojciech Dzierżanowskiabdeeaf2019-04-01 20:16:221746
1747 ResetStateForRestart();
[email protected]86ec30d2008-09-29 21:53:541748}
1749
[email protected]1c773ea12009-04-28 19:58:421750bool HttpNetworkTransaction::ShouldApplyProxyAuth() const {
Adam Rice425cf122015-01-19 06:18:241751 return UsingHttpProxyWithoutTunnel();
[email protected]1c773ea12009-04-28 19:58:421752}
license.botbf09a502008-08-24 00:55:551753
[email protected]1c773ea12009-04-28 19:58:421754bool HttpNetworkTransaction::ShouldApplyServerAuth() const {
Matt Menke25eaa432020-08-25 00:10:001755 return request_->privacy_mode == PRIVACY_MODE_DISABLED;
[email protected]1c773ea12009-04-28 19:58:421756}
1757
[email protected]e772db3f2010-07-12 18:11:131758int HttpNetworkTransaction::HandleAuthChallenge() {
[email protected]ad8e04a2010-11-01 04:16:271759 scoped_refptr<HttpResponseHeaders> headers(GetResponseHeaders());
[email protected]90499482013-06-01 00:39:501760 DCHECK(headers.get());
[email protected]c3b35c22008-09-27 03:19:421761
[email protected]0877e3d2009-10-17 22:29:571762 int status = headers->response_code();
[email protected]9094b602012-02-27 21:44:581763 if (status != HTTP_UNAUTHORIZED &&
1764 status != HTTP_PROXY_AUTHENTICATION_REQUIRED)
[email protected]c3b35c22008-09-27 03:19:421765 return OK;
[email protected]9094b602012-02-27 21:44:581766 HttpAuth::Target target = status == HTTP_PROXY_AUTHENTICATION_REQUIRED ?
[email protected]2227c692010-05-04 15:36:111767 HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER;
[email protected]038e9a32008-10-08 22:40:161768 if (target == HttpAuth::AUTH_PROXY && proxy_info_.is_direct())
1769 return ERR_UNEXPECTED_PROXY_AUTH;
[email protected]c3b35c22008-09-27 03:19:421770
[email protected]9094b602012-02-27 21:44:581771 // This case can trigger when an HTTPS server responds with a "Proxy
1772 // authentication required" status code through a non-authenticating
1773 // proxy.
[email protected]7a67a8152010-11-05 18:31:101774 if (!auth_controllers_[target].get())
1775 return ERR_UNEXPECTED_PROXY_AUTH;
1776
[email protected]a7ea8832010-07-12 17:54:541777 int rv = auth_controllers_[target]->HandleAuthChallenge(
Matt Menke25eaa432020-08-25 00:10:001778 headers, response_.ssl_info, !ShouldApplyServerAuth(), false, net_log_);
[email protected]228404f2010-06-24 04:31:411779 if (auth_controllers_[target]->HaveAuthHandler())
asanka5ffd5d72016-03-23 16:20:491780 pending_auth_target_ = target;
[email protected]228404f2010-06-24 04:31:411781
Emily Starkf2c9bbd2019-04-09 17:08:581782 auth_controllers_[target]->TakeAuthInfo(&response_.auth_challenge);
[email protected]228404f2010-06-24 04:31:411783
[email protected]228404f2010-06-24 04:31:411784 return rv;
[email protected]f9ee6b52008-11-08 06:46:231785}
1786
[email protected]8e6441ca2010-08-19 05:56:381787bool HttpNetworkTransaction::HaveAuth(HttpAuth::Target target) const {
1788 return auth_controllers_[target].get() &&
1789 auth_controllers_[target]->HaveAuth();
1790}
1791
[email protected]228404f2010-06-24 04:31:411792GURL HttpNetworkTransaction::AuthURL(HttpAuth::Target target) const {
1793 switch (target) {
[email protected]2df19bb2010-08-25 20:13:461794 case HttpAuth::AUTH_PROXY: {
[email protected]228404f2010-06-24 04:31:411795 if (!proxy_info_.proxy_server().is_valid() ||
1796 proxy_info_.proxy_server().is_direct()) {
1797 return GURL(); // There is no proxy server.
1798 }
Eric Romandbf7441f2020-07-28 07:05:021799 // TODO(https://crbug.com/1103768): Mapping proxy addresses to
1800 // URLs is a lossy conversion, shouldn't do this.
1801 const char* scheme =
1802 proxy_info_.is_secure_http_like() ? "https://" : "http://";
[email protected]2df19bb2010-08-25 20:13:461803 return GURL(scheme +
[email protected]2fbaecf22010-07-22 22:20:351804 proxy_info_.proxy_server().host_port_pair().ToString());
[email protected]2df19bb2010-08-25 20:13:461805 }
[email protected]228404f2010-06-24 04:31:411806 case HttpAuth::AUTH_SERVER:
[email protected]e69c1cd2014-07-29 07:42:291807 if (ForWebSocketHandshake()) {
Adam Rice9bd428b0a2019-02-15 06:31:361808 return net::ChangeWebSocketSchemeToHttpScheme(request_->url);
[email protected]e69c1cd2014-07-29 07:42:291809 }
[email protected]228404f2010-06-24 04:31:411810 return request_->url;
1811 default:
1812 return GURL();
1813 }
[email protected]c3b35c22008-09-27 03:19:421814}
1815
[email protected]831e4a32013-11-14 02:14:441816bool HttpNetworkTransaction::ForWebSocketHandshake() const {
[email protected]23d3e022013-11-23 20:38:141817 return websocket_handshake_stream_base_create_helper_ &&
1818 request_->url.SchemeIsWSOrWSS();
[email protected]831e4a32013-11-14 02:14:441819}
1820
ttuttle1f2d7e92015-04-28 16:17:471821void HttpNetworkTransaction::CopyConnectionAttemptsFromStreamRequest() {
1822 DCHECK(stream_request_);
1823
1824 // Since the transaction can restart with auth credentials, it may create a
1825 // stream more than once. Accumulate all of the connection attempts across
1826 // those streams by appending them to the vector:
1827 for (const auto& attempt : stream_request_->connection_attempts())
1828 connection_attempts_.push_back(attempt);
1829}
1830
eustasc7d27da2017-04-06 10:33:201831bool HttpNetworkTransaction::ContentEncodingsValid() const {
1832 HttpResponseHeaders* headers = GetResponseHeaders();
1833 DCHECK(headers);
1834
1835 std::string accept_encoding;
1836 request_headers_.GetHeader(HttpRequestHeaders::kAcceptEncoding,
1837 &accept_encoding);
1838 std::set<std::string> allowed_encodings;
Paul Jensene85e8152019-07-01 15:38:001839 if (!HttpUtil::ParseAcceptEncoding(accept_encoding, &allowed_encodings))
eustasc7d27da2017-04-06 10:33:201840 return false;
eustasc7d27da2017-04-06 10:33:201841
1842 std::string content_encoding;
1843 headers->GetNormalizedHeader("Content-Encoding", &content_encoding);
1844 std::set<std::string> used_encodings;
Paul Jensene85e8152019-07-01 15:38:001845 if (!HttpUtil::ParseContentEncoding(content_encoding, &used_encodings))
eustasc7d27da2017-04-06 10:33:201846 return false;
eustasc7d27da2017-04-06 10:33:201847
1848 // When "Accept-Encoding" is not specified, it is parsed as "*".
1849 // If "*" encoding is advertised, then any encoding should be "accepted".
1850 // This does not mean, that it will be successfully decoded.
1851 if (allowed_encodings.find("*") != allowed_encodings.end())
1852 return true;
1853
sky50576f32017-05-01 19:28:031854 bool result = true;
eustasc7d27da2017-04-06 10:33:201855 for (auto const& encoding : used_encodings) {
1856 SourceStream::SourceType source_type =
1857 FilterSourceStream::ParseEncodingType(encoding);
1858 // We don't reject encodings we are not aware. They just will not decode.
1859 if (source_type == SourceStream::TYPE_UNKNOWN)
1860 continue;
1861 if (allowed_encodings.find(encoding) == allowed_encodings.end()) {
sky50576f32017-05-01 19:28:031862 result = false;
1863 break;
eustasc7d27da2017-04-06 10:33:201864 }
1865 }
sky50576f32017-05-01 19:28:031866
1867 // Temporary workaround for http://crbug.com/714514
1868 if (headers->IsRedirect(nullptr)) {
1869 UMA_HISTOGRAM_BOOLEAN("Net.RedirectWithUnadvertisedContentEncoding",
1870 !result);
1871 return true;
1872 }
1873
1874 return result;
eustasc7d27da2017-04-06 10:33:201875}
1876
[email protected]c3b35c22008-09-27 03:19:421877} // namespace net