blob: f4df073b4bba5ad905631653d2cba46820c0daa7 [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>
8#include <vector>
9
[email protected]49639fa2011-12-20 23:22:4110#include "base/bind.h"
11#include "base/bind_helpers.h"
[email protected]68bf9152008-09-25 19:47:3012#include "base/compiler_specific.h"
[email protected]270c6412010-03-29 22:02:4713#include "base/format_macros.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]835d7c82010-10-14 04:38:3815#include "base/metrics/field_trial.h"
16#include "base/metrics/histogram.h"
17#include "base/metrics/stats_counters.h"
[email protected]7286e3fc2011-07-19 22:13:2418#include "base/stl_util.h"
[email protected]125ef482013-06-11 18:32:4719#include "base/strings/string_number_conversions.h"
20#include "base/strings/string_util.h"
21#include "base/strings/stringprintf.h"
[email protected]3d498f72013-10-28 21:17:4022#include "base/time/time.h"
[email protected]db74b0102012-05-31 19:55:5323#include "base/values.h"
[email protected]68bf9152008-09-25 19:47:3024#include "build/build_config.h"
[email protected]277d5942010-08-11 21:02:3525#include "net/base/auth.h"
[email protected]2d6728692011-03-12 01:39:5526#include "net/base/host_port_pair.h"
[email protected]74a85ce2009-02-12 00:03:1927#include "net/base/io_buffer.h"
initial.commit586acc5fe2008-07-26 22:42:5228#include "net/base/load_flags.h"
[email protected]58e32bb2013-01-21 18:23:2529#include "net/base/load_timing_info.h"
[email protected]597cf6e2009-05-29 09:43:2630#include "net/base/net_errors.h"
[email protected]c3b35c22008-09-27 03:19:4231#include "net/base/net_util.h"
initial.commit586acc5fe2008-07-26 22:42:5232#include "net/base/upload_data_stream.h"
[email protected]c3b35c22008-09-27 03:19:4233#include "net/http/http_auth.h"
34#include "net/http/http_auth_handler.h"
[email protected]fa82f932010-05-20 11:09:2435#include "net/http/http_auth_handler_factory.h"
[email protected]8d5a34e2009-06-11 21:21:3636#include "net/http/http_basic_stream.h"
initial.commit586acc5fe2008-07-26 22:42:5237#include "net/http/http_chunked_decoder.h"
38#include "net/http/http_network_session.h"
[email protected]a7ea8832010-07-12 17:54:5439#include "net/http/http_proxy_client_socket.h"
[email protected]e772db3f2010-07-12 18:11:1340#include "net/http/http_proxy_client_socket_pool.h"
[email protected]270c6412010-03-29 22:02:4741#include "net/http/http_request_headers.h"
initial.commit586acc5fe2008-07-26 22:42:5242#include "net/http/http_request_info.h"
[email protected]319d9e6f2009-02-18 19:47:2143#include "net/http/http_response_headers.h"
[email protected]0877e3d2009-10-17 22:29:5744#include "net/http/http_response_info.h"
[email protected]17291a022011-10-10 07:32:5345#include "net/http/http_server_properties.h"
[email protected]9094b602012-02-27 21:44:5846#include "net/http/http_status_code.h"
[email protected]92b9a3e2012-11-09 08:52:5247#include "net/http/http_stream_base.h"
[email protected]102e27c2011-02-23 01:01:3148#include "net/http/http_stream_factory.h"
initial.commit586acc5fe2008-07-26 22:42:5249#include "net/http/http_util.h"
[email protected]158ac972013-04-19 23:29:2350#include "net/http/transport_security_state.h"
[email protected]d7f16632010-03-29 18:02:3651#include "net/http/url_security_manager.h"
[email protected]f7984fc62009-06-22 23:26:4452#include "net/socket/client_socket_factory.h"
[email protected]a796bcec2010-03-22 17:17:2653#include "net/socket/socks_client_socket_pool.h"
[email protected]f7984fc62009-06-22 23:26:4454#include "net/socket/ssl_client_socket.h"
[email protected]e60e47a2010-07-14 03:37:1855#include "net/socket/ssl_client_socket_pool.h"
[email protected]ab739042011-04-07 15:22:2856#include "net/socket/transport_client_socket_pool.h"
[email protected]e00bfd572014-04-30 08:06:4357#include "net/spdy/hpack_huffman_aggregator.h"
[email protected]65d56aa2010-06-14 04:13:4058#include "net/spdy/spdy_http_stream.h"
[email protected]dab9c7d2010-02-06 21:44:3259#include "net/spdy/spdy_session.h"
60#include "net/spdy/spdy_session_pool.h"
[email protected]536fd0b2013-03-14 17:41:5761#include "net/ssl/ssl_cert_request_info.h"
62#include "net/ssl/ssl_connection_status_flags.h"
[email protected]f89276a72013-07-12 06:41:5463#include "url/gurl.h"
initial.commit586acc5fe2008-07-26 22:42:5264
[email protected]a4fd43a2013-12-13 20:42:2765#if defined(SPDY_PROXY_AUTH_ORIGIN)
[email protected]59ca4da22014-02-06 00:45:2966#include <algorithm>
[email protected]a4fd43a2013-12-13 20:42:2767#include "net/proxy/proxy_server.h"
68#endif
69
70
[email protected]e1acf6f2008-10-27 20:43:3371using base::Time;
[email protected]a4fd43a2013-12-13 20:42:2772using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:3373
initial.commit586acc5fe2008-07-26 22:42:5274namespace net {
75
[email protected]1c773ea12009-04-28 19:58:4276namespace {
77
[email protected]30d4c022013-07-18 22:58:1678void ProcessAlternateProtocol(
[email protected]d7599122014-05-24 03:37:2379 HttpNetworkSession* session,
[email protected]30d4c022013-07-18 22:58:1680 const HttpResponseHeaders& headers,
81 const HostPortPair& http_host_port_pair) {
[email protected]287d9412014-07-08 23:01:0082 if (!headers.HasHeader(kAlternateProtocolHeader))
[email protected]ff4a6492014-07-08 19:49:3883 return;
[email protected]287d9412014-07-08 23:01:0084
85 std::vector<std::string> alternate_protocol_values;
86 void* iter = NULL;
87 std::string alternate_protocol_str;
88 while (headers.EnumerateHeader(&iter, kAlternateProtocolHeader,
89 &alternate_protocol_str)) {
90 alternate_protocol_values.push_back(alternate_protocol_str);
[email protected]564b4912010-03-09 16:30:4291 }
92
[email protected]d7599122014-05-24 03:37:2393 session->http_stream_factory()->ProcessAlternateProtocol(
94 session->http_server_properties(),
[email protected]287d9412014-07-08 23:01:0095 alternate_protocol_values,
[email protected]d7599122014-05-24 03:37:2396 http_host_port_pair,
97 *session);
[email protected]f45c1ee2010-08-03 00:54:3098}
99
[email protected]a1cb2cd2011-02-05 02:02:08100// Returns true if |error| is a client certificate authentication error.
101bool IsClientCertificateError(int error) {
102 switch (error) {
103 case ERR_BAD_SSL_CLIENT_AUTH_CERT:
104 case ERR_SSL_CLIENT_AUTH_PRIVATE_KEY_ACCESS_DENIED:
105 case ERR_SSL_CLIENT_AUTH_CERT_NO_PRIVATE_KEY:
106 case ERR_SSL_CLIENT_AUTH_SIGNATURE_FAILED:
107 return true;
108 default:
109 return false;
110 }
111}
112
[email protected]ea5ef4c2013-06-13 22:50:27113base::Value* NetLogSSLVersionFallbackCallback(
114 const GURL* url,
115 int net_error,
116 uint16 version_before,
117 uint16 version_after,
118 NetLog::LogLevel /* log_level */) {
119 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]b6754252012-06-13 23:14:38120 dict->SetString("host_and_port", GetHostAndPort(*url));
121 dict->SetInteger("net_error", net_error);
122 dict->SetInteger("version_before", version_before);
123 dict->SetInteger("version_after", version_after);
124 return dict;
125}
[email protected]db74b0102012-05-31 19:55:53126
[email protected]1c773ea12009-04-28 19:58:42127} // namespace
128
initial.commit586acc5fe2008-07-26 22:42:52129//-----------------------------------------------------------------------------
130
[email protected]262eec82013-03-19 21:01:36131HttpNetworkTransaction::HttpNetworkTransaction(RequestPriority priority,
132 HttpNetworkSession* session)
[email protected]0757e7702009-03-27 04:00:22133 : pending_auth_target_(HttpAuth::AUTH_NONE),
[email protected]aa249b52013-04-30 01:04:32134 io_callback_(base::Bind(&HttpNetworkTransaction::OnIOComplete,
135 base::Unretained(this))),
initial.commit586acc5fe2008-07-26 22:42:52136 session_(session),
137 request_(NULL),
[email protected]262eec82013-03-19 21:01:36138 priority_(priority),
[email protected]0877e3d2009-10-17 22:29:57139 headers_valid_(false),
[email protected]8e3d2d32010-06-13 18:46:23140 logged_response_time_(false),
[email protected]a53e4d12013-12-07 16:37:24141 fallback_error_code_(ERR_SSL_INAPPROPRIATE_FALLBACK),
[email protected]b94f92d2010-10-27 16:45:20142 request_headers_(),
initial.commit586acc5fe2008-07-26 22:42:52143 read_buf_len_(0),
[email protected]b8015c42013-12-24 15:18:19144 total_received_bytes_(0),
[email protected]a7ea8832010-07-12 17:54:54145 next_state_(STATE_NONE),
[email protected]831e4a32013-11-14 02:14:44146 establishing_tunnel_(false),
147 websocket_handshake_stream_base_create_helper_(NULL) {
[email protected]102957f2011-09-02 17:10:14148 session->ssl_config_service()->GetSSLConfig(&server_ssl_config_);
[email protected]d7599122014-05-24 03:37:23149 session->GetNextProtos(&server_ssl_config_.next_protos);
[email protected]99ffa5a2011-10-06 04:20:19150 proxy_ssl_config_ = server_ssl_config_;
[email protected]3ce7df0f2010-03-03 00:30:50151}
152
[email protected]0b0bf032010-09-21 18:08:50153HttpNetworkTransaction::~HttpNetworkTransaction() {
154 if (stream_.get()) {
155 HttpResponseHeaders* headers = GetResponseHeaders();
156 // TODO(mbelshe): The stream_ should be able to compute whether or not the
157 // stream should be kept alive. No reason to compute here
158 // and pass it in.
159 bool try_to_keep_alive =
160 next_state_ == STATE_NONE &&
161 stream_->CanFindEndOfResponse() &&
162 (!headers || headers->IsKeepAlive());
163 if (!try_to_keep_alive) {
164 stream_->Close(true /* not reusable */);
165 } else {
166 if (stream_->IsResponseBodyComplete()) {
167 // If the response body is complete, we can just reuse the socket.
168 stream_->Close(false /* reusable */);
[email protected]3a8d6852011-03-11 23:43:44169 } else if (stream_->IsSpdyHttpStream()) {
170 // Doesn't really matter for SpdyHttpStream. Just close it.
171 stream_->Close(true /* not reusable */);
[email protected]0b0bf032010-09-21 18:08:50172 } else {
173 // Otherwise, we try to drain the response body.
[email protected]92b9a3e2012-11-09 08:52:52174 HttpStreamBase* stream = stream_.release();
[email protected]3fe8d2f82013-10-17 08:56:07175 stream->Drain(session_);
[email protected]0b0bf032010-09-21 18:08:50176 }
177 }
178 }
[email protected]02cad5d2013-10-02 08:14:03179
180 if (request_ && request_->upload_data_stream)
181 request_->upload_data_stream->Reset(); // Invalidate pending callbacks.
[email protected]0b0bf032010-09-21 18:08:50182}
183
[email protected]684970b2009-08-14 04:54:46184int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info,
[email protected]49639fa2011-12-20 23:22:41185 const CompletionCallback& callback,
[email protected]9e743cd2010-03-16 07:03:53186 const BoundNetLog& net_log) {
[email protected]5e2e6c77d12009-12-24 21:57:16187 SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count");
[email protected]5d0153c512009-01-12 19:08:36188
[email protected]9e743cd2010-03-16 07:03:53189 net_log_ = net_log;
[email protected]96d570e42008-08-05 22:43:04190 request_ = request_info;
[email protected]21b316a2009-03-23 18:25:06191 start_time_ = base::Time::Now();
[email protected]96d570e42008-08-05 22:43:04192
[email protected]99ffa5a2011-10-06 04:20:19193 if (request_->load_flags & LOAD_DISABLE_CERT_REVOCATION_CHECKING) {
[email protected]102957f2011-09-02 17:10:14194 server_ssl_config_.rev_checking_enabled = false;
[email protected]99ffa5a2011-10-06 04:20:19195 proxy_ssl_config_.rev_checking_enabled = false;
196 }
[email protected]6fbac162011-06-20 00:29:04197
[email protected]1ea4f46a2014-04-22 22:33:56198 // Channel ID is disabled if privacy mode is enabled for this request.
[email protected]66eeb52e2014-05-22 06:53:49199 if (request_->privacy_mode == PRIVACY_MODE_ENABLED)
200 server_ssl_config_.channel_id_enabled = false;
[email protected]e6d017652013-05-17 18:01:40201
[email protected]1826a402014-01-08 15:40:48202 next_state_ = STATE_NOTIFY_BEFORE_CREATE_STREAM;
[email protected]96d570e42008-08-05 22:43:04203 int rv = DoLoop(OK);
204 if (rv == ERR_IO_PENDING)
[email protected]49639fa2011-12-20 23:22:41205 callback_ = callback;
[email protected]96d570e42008-08-05 22:43:04206 return rv;
207}
208
209int HttpNetworkTransaction::RestartIgnoringLastError(
[email protected]49639fa2011-12-20 23:22:41210 const CompletionCallback& callback) {
[email protected]8e6441ca2010-08-19 05:56:38211 DCHECK(!stream_.get());
212 DCHECK(!stream_request_.get());
213 DCHECK_EQ(STATE_NONE, next_state_);
214
[email protected]82918cc2010-08-25 17:24:50215 next_state_ = STATE_CREATE_STREAM;
[email protected]8e6441ca2010-08-19 05:56:38216
[email protected]ccb40e52008-09-17 20:54:40217 int rv = DoLoop(OK);
218 if (rv == ERR_IO_PENDING)
[email protected]49639fa2011-12-20 23:22:41219 callback_ = callback;
[email protected]aaead502008-10-15 00:20:11220 return rv;
[email protected]96d570e42008-08-05 22:43:04221}
222
[email protected]0b45559b2009-06-12 21:45:11223int HttpNetworkTransaction::RestartWithCertificate(
[email protected]49639fa2011-12-20 23:22:41224 X509Certificate* client_cert, const CompletionCallback& callback) {
[email protected]8e6441ca2010-08-19 05:56:38225 // In HandleCertificateRequest(), we always tear down existing stream
226 // requests to force a new connection. So we shouldn't have one here.
227 DCHECK(!stream_request_.get());
228 DCHECK(!stream_.get());
229 DCHECK_EQ(STATE_NONE, next_state_);
230
[email protected]102957f2011-09-02 17:10:14231 SSLConfig* ssl_config = response_.cert_request_info->is_proxy ?
232 &proxy_ssl_config_ : &server_ssl_config_;
233 ssl_config->send_client_cert = true;
234 ssl_config->client_cert = client_cert;
[email protected]ec229bc92010-11-22 09:51:45235 session_->ssl_client_auth_cache()->Add(
236 response_.cert_request_info->host_and_port, client_cert);
[email protected]0b45559b2009-06-12 21:45:11237 // Reset the other member variables.
238 // Note: this is necessary only with SSL renegotiation.
239 ResetStateForRestart();
[email protected]82918cc2010-08-25 17:24:50240 next_state_ = STATE_CREATE_STREAM;
[email protected]0b45559b2009-06-12 21:45:11241 int rv = DoLoop(OK);
242 if (rv == ERR_IO_PENDING)
[email protected]49639fa2011-12-20 23:22:41243 callback_ = callback;
[email protected]0b45559b2009-06-12 21:45:11244 return rv;
245}
246
[email protected]49639fa2011-12-20 23:22:41247int HttpNetworkTransaction::RestartWithAuth(
248 const AuthCredentials& credentials, const CompletionCallback& callback) {
[email protected]0757e7702009-03-27 04:00:22249 HttpAuth::Target target = pending_auth_target_;
250 if (target == HttpAuth::AUTH_NONE) {
251 NOTREACHED();
252 return ERR_UNEXPECTED;
253 }
[email protected]0757e7702009-03-27 04:00:22254 pending_auth_target_ = HttpAuth::AUTH_NONE;
[email protected]c3b35c22008-09-27 03:19:42255
[email protected]f3cf9802011-10-28 18:44:58256 auth_controllers_[target]->ResetAuth(credentials);
[email protected]e772db3f2010-07-12 18:11:13257
[email protected]49639fa2011-12-20 23:22:41258 DCHECK(callback_.is_null());
[email protected]8e6441ca2010-08-19 05:56:38259
260 int rv = OK;
261 if (target == HttpAuth::AUTH_PROXY && establishing_tunnel_) {
262 // In this case, we've gathered credentials for use with proxy
263 // authentication of a tunnel.
[email protected]82918cc2010-08-25 17:24:50264 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38265 DCHECK(stream_request_ != NULL);
[email protected]394816e92010-08-03 07:38:59266 auth_controllers_[target] = NULL;
[email protected]a7ea8832010-07-12 17:54:54267 ResetStateForRestart();
[email protected]f3cf9802011-10-28 18:44:58268 rv = stream_request_->RestartTunnelWithProxyAuth(credentials);
[email protected]a7ea8832010-07-12 17:54:54269 } else {
[email protected]8e6441ca2010-08-19 05:56:38270 // In this case, we've gathered credentials for the server or the proxy
271 // but it is not during the tunneling phase.
272 DCHECK(stream_request_ == NULL);
[email protected]a7ea8832010-07-12 17:54:54273 PrepareForAuthRestart(target);
[email protected]8e6441ca2010-08-19 05:56:38274 rv = DoLoop(OK);
[email protected]a7ea8832010-07-12 17:54:54275 }
[email protected]c3b35c22008-09-27 03:19:42276
[email protected]c3b35c22008-09-27 03:19:42277 if (rv == ERR_IO_PENDING)
[email protected]49639fa2011-12-20 23:22:41278 callback_ = callback;
[email protected]c3b35c22008-09-27 03:19:42279 return rv;
[email protected]96d570e42008-08-05 22:43:04280}
281
[email protected]f9ee6b52008-11-08 06:46:23282void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) {
283 DCHECK(HaveAuth(target));
[email protected]8e6441ca2010-08-19 05:56:38284 DCHECK(!stream_request_.get());
285
[email protected]2d2697f92009-02-18 21:00:32286 bool keep_alive = false;
[email protected]0877e3d2009-10-17 22:29:57287 // Even if the server says the connection is keep-alive, we have to be
288 // able to find the end of each response in order to reuse the connection.
289 if (GetResponseHeaders()->IsKeepAlive() &&
[email protected]351ab642010-08-05 16:55:31290 stream_->CanFindEndOfResponse()) {
[email protected]0877e3d2009-10-17 22:29:57291 // If the response body hasn't been completely read, we need to drain
292 // it first.
[email protected]351ab642010-08-05 16:55:31293 if (!stream_->IsResponseBodyComplete()) {
[email protected]2d2697f92009-02-18 21:00:32294 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART;
[email protected]0877e3d2009-10-17 22:29:57295 read_buf_ = new IOBuffer(kDrainBodyBufferSize); // A bit bucket.
[email protected]2d2697f92009-02-18 21:00:32296 read_buf_len_ = kDrainBodyBufferSize;
297 return;
298 }
[email protected]0877e3d2009-10-17 22:29:57299 keep_alive = true;
[email protected]37832c6d2009-06-05 19:44:09300 }
301
[email protected]2d2697f92009-02-18 21:00:32302 // We don't need to drain the response body, so we act as if we had drained
303 // the response body.
304 DidDrainBodyForAuthRestart(keep_alive);
305}
306
307void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) {
[email protected]8e6441ca2010-08-19 05:56:38308 DCHECK(!stream_request_.get());
309
310 if (stream_.get()) {
[email protected]b8015c42013-12-24 15:18:19311 total_received_bytes_ += stream_->GetTotalReceivedBytes();
[email protected]697ef4c2010-10-14 16:38:58312 HttpStream* new_stream = NULL;
[email protected]2d0a4f92011-05-05 16:38:46313 if (keep_alive && stream_->IsConnectionReusable()) {
[email protected]8e6441ca2010-08-19 05:56:38314 // We should call connection_->set_idle_time(), but this doesn't occur
315 // often enough to be worth the trouble.
316 stream_->SetConnectionReused();
[email protected]92b9a3e2012-11-09 08:52:52317 new_stream =
318 static_cast<HttpStream*>(stream_.get())->RenewStreamForAuth();
[email protected]8e6441ca2010-08-19 05:56:38319 }
[email protected]697ef4c2010-10-14 16:38:58320
321 if (!new_stream) {
[email protected]2d0a4f92011-05-05 16:38:46322 // Close the stream and mark it as not_reusable. Even in the
323 // keep_alive case, we've determined that the stream_ is not
324 // reusable if new_stream is NULL.
325 stream_->Close(true);
[email protected]697ef4c2010-10-14 16:38:58326 next_state_ = STATE_CREATE_STREAM;
327 } else {
[email protected]b8015c42013-12-24 15:18:19328 // Renewed streams shouldn't carry over received bytes.
329 DCHECK_EQ(0, new_stream->GetTotalReceivedBytes());
[email protected]697ef4c2010-10-14 16:38:58330 next_state_ = STATE_INIT_STREAM;
331 }
332 stream_.reset(new_stream);
[email protected]2d2697f92009-02-18 21:00:32333 }
[email protected]f9ee6b52008-11-08 06:46:23334
335 // Reset the other member variables.
[email protected]697ef4c2010-10-14 16:38:58336 ResetStateForAuthRestart();
[email protected]f9ee6b52008-11-08 06:46:23337}
338
[email protected]8e6441ca2010-08-19 05:56:38339bool HttpNetworkTransaction::IsReadyToRestartForAuth() {
340 return pending_auth_target_ != HttpAuth::AUTH_NONE &&
341 HaveAuth(pending_auth_target_);
342}
343
[email protected]9dea9e1f2009-01-29 00:30:47344int HttpNetworkTransaction::Read(IOBuffer* buf, int buf_len,
[email protected]49639fa2011-12-20 23:22:41345 const CompletionCallback& callback) {
[email protected]96d570e42008-08-05 22:43:04346 DCHECK(buf);
[email protected]e0c27be2009-07-15 13:09:35347 DCHECK_LT(0, buf_len);
[email protected]96d570e42008-08-05 22:43:04348
[email protected]1f14a912009-12-21 20:32:44349 State next_state = STATE_NONE;
[email protected]96d570e42008-08-05 22:43:04350
[email protected]ad8e04a2010-11-01 04:16:27351 scoped_refptr<HttpResponseHeaders> headers(GetResponseHeaders());
[email protected]8e6441ca2010-08-19 05:56:38352 if (headers_valid_ && headers.get() && stream_request_.get()) {
[email protected]8a1f3312010-05-25 19:25:04353 // We're trying to read the body of the response but we're still trying
[email protected]511f6f52010-12-17 03:58:29354 // to establish an SSL tunnel through an HTTP proxy. We can't read these
[email protected]8a1f3312010-05-25 19:25:04355 // bytes when establishing a tunnel because they might be controlled by
356 // an active network attacker. We don't worry about this for HTTP
357 // because an active network attacker can already control HTTP sessions.
[email protected]511f6f52010-12-17 03:58:29358 // We reach this case when the user cancels a 407 proxy auth prompt. We
359 // also don't worry about this for an HTTPS Proxy, because the
360 // communication with the proxy is secure.
[email protected]8a1f3312010-05-25 19:25:04361 // See http://crbug.com/8473.
[email protected]2df19bb2010-08-25 20:13:46362 DCHECK(proxy_info_.is_http() || proxy_info_.is_https());
[email protected]9094b602012-02-27 21:44:58363 DCHECK_EQ(headers->response_code(), HTTP_PROXY_AUTHENTICATION_REQUIRED);
[email protected]a7ea8832010-07-12 17:54:54364 LOG(WARNING) << "Blocked proxy response with status "
365 << headers->response_code() << " to CONNECT request for "
366 << GetHostAndPort(request_->url) << ".";
[email protected]8a1f3312010-05-25 19:25:04367 return ERR_TUNNEL_CONNECTION_FAILED;
[email protected]a8e9b162009-03-12 00:06:44368 }
369
[email protected]e60e47a2010-07-14 03:37:18370 // Are we using SPDY or HTTP?
[email protected]351ab642010-08-05 16:55:31371 next_state = STATE_READ_BODY;
[email protected]e60e47a2010-07-14 03:37:18372
[email protected]96d570e42008-08-05 22:43:04373 read_buf_ = buf;
374 read_buf_len_ = buf_len;
375
[email protected]1f14a912009-12-21 20:32:44376 next_state_ = next_state;
[email protected]96d570e42008-08-05 22:43:04377 int rv = DoLoop(OK);
378 if (rv == ERR_IO_PENDING)
[email protected]49639fa2011-12-20 23:22:41379 callback_ = callback;
[email protected]96d570e42008-08-05 22:43:04380 return rv;
381}
382
[email protected]8cd06c02014-01-25 07:50:14383void HttpNetworkTransaction::StopCaching() {}
384
[email protected]79e1fd62013-06-20 06:50:04385bool HttpNetworkTransaction::GetFullRequestHeaders(
386 HttpRequestHeaders* headers) const {
387 // TODO(ttuttle): Make sure we've populated request_headers_.
388 *headers = request_headers_;
389 return true;
390}
391
[email protected]b8015c42013-12-24 15:18:19392int64 HttpNetworkTransaction::GetTotalReceivedBytes() const {
393 int64 total_received_bytes = total_received_bytes_;
394 if (stream_)
395 total_received_bytes += stream_->GetTotalReceivedBytes();
396 return total_received_bytes;
397}
398
[email protected]8cd06c02014-01-25 07:50:14399void HttpNetworkTransaction::DoneReading() {}
400
[email protected]96d570e42008-08-05 22:43:04401const HttpResponseInfo* HttpNetworkTransaction::GetResponseInfo() const {
[email protected]90499482013-06-01 00:39:50402 return ((headers_valid_ && response_.headers.get()) ||
403 response_.ssl_info.cert.get() || response_.cert_request_info.get())
404 ? &response_
405 : NULL;
[email protected]96d570e42008-08-05 22:43:04406}
407
408LoadState HttpNetworkTransaction::GetLoadState() const {
409 // TODO(wtc): Define a new LoadState value for the
410 // STATE_INIT_CONNECTION_COMPLETE state, which delays the HTTP request.
411 switch (next_state_) {
[email protected]1826a402014-01-08 15:40:48412 case STATE_CREATE_STREAM:
413 return LOAD_STATE_WAITING_FOR_DELEGATE;
[email protected]82918cc2010-08-25 17:24:50414 case STATE_CREATE_STREAM_COMPLETE:
[email protected]8e6441ca2010-08-19 05:56:38415 return stream_request_->GetLoadState();
[email protected]044de0642010-06-17 10:42:15416 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE:
417 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE:
[email protected]0877e3d2009-10-17 22:29:57418 case STATE_SEND_REQUEST_COMPLETE:
[email protected]96d570e42008-08-05 22:43:04419 return LOAD_STATE_SENDING_REQUEST;
420 case STATE_READ_HEADERS_COMPLETE:
421 return LOAD_STATE_WAITING_FOR_RESPONSE;
422 case STATE_READ_BODY_COMPLETE:
423 return LOAD_STATE_READING_RESPONSE;
424 default:
425 return LOAD_STATE_IDLE;
426 }
427}
428
[email protected]196d18a2012-08-30 03:47:31429UploadProgress HttpNetworkTransaction::GetUploadProgress() const {
[email protected]351ab642010-08-05 16:55:31430 if (!stream_.get())
[email protected]196d18a2012-08-30 03:47:31431 return UploadProgress();
[email protected]96d570e42008-08-05 22:43:04432
[email protected]92b9a3e2012-11-09 08:52:52433 // TODO(bashi): This cast is temporary. Remove later.
434 return static_cast<HttpStream*>(stream_.get())->GetUploadProgress();
[email protected]96d570e42008-08-05 22:43:04435}
436
[email protected]8cd06c02014-01-25 07:50:14437void HttpNetworkTransaction::SetQuicServerInfo(
438 QuicServerInfo* quic_server_info) {}
439
[email protected]5033ab82013-03-22 20:17:46440bool HttpNetworkTransaction::GetLoadTimingInfo(
441 LoadTimingInfo* load_timing_info) const {
442 if (!stream_ || !stream_->GetLoadTimingInfo(load_timing_info))
443 return false;
444
445 load_timing_info->proxy_resolve_start =
446 proxy_info_.proxy_resolve_start_time();
447 load_timing_info->proxy_resolve_end = proxy_info_.proxy_resolve_end_time();
448 load_timing_info->send_start = send_start_time_;
449 load_timing_info->send_end = send_end_time_;
[email protected]5033ab82013-03-22 20:17:46450 return true;
451}
452
453void HttpNetworkTransaction::SetPriority(RequestPriority priority) {
454 priority_ = priority;
[email protected]bf828982013-08-14 18:01:47455 if (stream_request_)
456 stream_request_->SetPriority(priority);
[email protected]e86839fd2013-08-14 18:29:03457 if (stream_)
458 stream_->SetPriority(priority);
[email protected]5033ab82013-03-22 20:17:46459}
460
[email protected]831e4a32013-11-14 02:14:44461void HttpNetworkTransaction::SetWebSocketHandshakeStreamCreateHelper(
462 WebSocketHandshakeStreamBase::CreateHelper* create_helper) {
463 websocket_handshake_stream_base_create_helper_ = create_helper;
464}
465
[email protected]1826a402014-01-08 15:40:48466void HttpNetworkTransaction::SetBeforeNetworkStartCallback(
467 const BeforeNetworkStartCallback& callback) {
468 before_network_start_callback_ = callback;
469}
470
[email protected]597a1ab2014-06-26 08:12:27471void HttpNetworkTransaction::SetBeforeProxyHeadersSentCallback(
472 const BeforeProxyHeadersSentCallback& callback) {
473 before_proxy_headers_sent_callback_ = callback;
474}
475
[email protected]1826a402014-01-08 15:40:48476int HttpNetworkTransaction::ResumeNetworkStart() {
477 DCHECK_EQ(next_state_, STATE_CREATE_STREAM);
478 return DoLoop(OK);
479}
480
[email protected]102e27c2011-02-23 01:01:31481void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config,
482 const ProxyInfo& used_proxy_info,
[email protected]92b9a3e2012-11-09 08:52:52483 HttpStreamBase* stream) {
[email protected]82918cc2010-08-25 17:24:50484 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38485 DCHECK(stream_request_.get());
486
[email protected]b8015c42013-12-24 15:18:19487 if (stream_)
488 total_received_bytes_ += stream_->GetTotalReceivedBytes();
[email protected]8e6441ca2010-08-19 05:56:38489 stream_.reset(stream);
[email protected]102957f2011-09-02 17:10:14490 server_ssl_config_ = used_ssl_config;
[email protected]102e27c2011-02-23 01:01:31491 proxy_info_ = used_proxy_info;
[email protected]8e6441ca2010-08-19 05:56:38492 response_.was_npn_negotiated = stream_request_->was_npn_negotiated();
[email protected]c30bcce2011-12-20 17:50:51493 response_.npn_negotiated_protocol = SSLClientSocket::NextProtoToString(
494 stream_request_->protocol_negotiated());
[email protected]8e6441ca2010-08-19 05:56:38495 response_.was_fetched_via_spdy = stream_request_->using_spdy();
496 response_.was_fetched_via_proxy = !proxy_info_.is_direct();
[email protected]d8fc4722014-06-13 13:17:15497 if (response_.was_fetched_via_proxy && !proxy_info_.is_empty())
498 response_.proxy_server = proxy_info_.proxy_server().host_port_pair();
[email protected]8e6441ca2010-08-19 05:56:38499 OnIOComplete(OK);
500}
501
[email protected]a9cf2b92013-10-30 12:08:49502void HttpNetworkTransaction::OnWebSocketHandshakeStreamReady(
[email protected]3732cea2013-06-21 06:50:50503 const SSLConfig& used_ssl_config,
504 const ProxyInfo& used_proxy_info,
[email protected]a9cf2b92013-10-30 12:08:49505 WebSocketHandshakeStreamBase* stream) {
[email protected]831e4a32013-11-14 02:14:44506 OnStreamReady(used_ssl_config, used_proxy_info, stream);
[email protected]3732cea2013-06-21 06:50:50507}
508
[email protected]102e27c2011-02-23 01:01:31509void HttpNetworkTransaction::OnStreamFailed(int result,
510 const SSLConfig& used_ssl_config) {
[email protected]82918cc2010-08-25 17:24:50511 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38512 DCHECK_NE(OK, result);
513 DCHECK(stream_request_.get());
514 DCHECK(!stream_.get());
[email protected]102957f2011-09-02 17:10:14515 server_ssl_config_ = used_ssl_config;
[email protected]8e6441ca2010-08-19 05:56:38516
517 OnIOComplete(result);
518}
519
[email protected]102e27c2011-02-23 01:01:31520void HttpNetworkTransaction::OnCertificateError(
521 int result,
522 const SSLConfig& used_ssl_config,
523 const SSLInfo& ssl_info) {
[email protected]82918cc2010-08-25 17:24:50524 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38525 DCHECK_NE(OK, result);
526 DCHECK(stream_request_.get());
527 DCHECK(!stream_.get());
528
529 response_.ssl_info = ssl_info;
[email protected]102957f2011-09-02 17:10:14530 server_ssl_config_ = used_ssl_config;
[email protected]8e6441ca2010-08-19 05:56:38531
532 // TODO(mbelshe): For now, we're going to pass the error through, and that
533 // will close the stream_request in all cases. This means that we're always
[email protected]82918cc2010-08-25 17:24:50534 // going to restart an entire STATE_CREATE_STREAM, even if the connection is
535 // good and the user chooses to ignore the error. This is not ideal, but not
536 // the end of the world either.
[email protected]8e6441ca2010-08-19 05:56:38537
538 OnIOComplete(result);
539}
540
541void HttpNetworkTransaction::OnNeedsProxyAuth(
[email protected]6dc476da2010-09-01 04:43:50542 const HttpResponseInfo& proxy_response,
[email protected]102e27c2011-02-23 01:01:31543 const SSLConfig& used_ssl_config,
544 const ProxyInfo& used_proxy_info,
[email protected]6dc476da2010-09-01 04:43:50545 HttpAuthController* auth_controller) {
[email protected]8e6441ca2010-08-19 05:56:38546 DCHECK(stream_request_.get());
[email protected]82918cc2010-08-25 17:24:50547 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38548
549 establishing_tunnel_ = true;
550 response_.headers = proxy_response.headers;
551 response_.auth_challenge = proxy_response.auth_challenge;
552 headers_valid_ = true;
[email protected]102957f2011-09-02 17:10:14553 server_ssl_config_ = used_ssl_config;
[email protected]102e27c2011-02-23 01:01:31554 proxy_info_ = used_proxy_info;
[email protected]8e6441ca2010-08-19 05:56:38555
556 auth_controllers_[HttpAuth::AUTH_PROXY] = auth_controller;
557 pending_auth_target_ = HttpAuth::AUTH_PROXY;
558
559 DoCallback(OK);
560}
561
562void HttpNetworkTransaction::OnNeedsClientAuth(
[email protected]102e27c2011-02-23 01:01:31563 const SSLConfig& used_ssl_config,
[email protected]6dc476da2010-09-01 04:43:50564 SSLCertRequestInfo* cert_info) {
[email protected]82918cc2010-08-25 17:24:50565 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
[email protected]8e6441ca2010-08-19 05:56:38566
[email protected]102957f2011-09-02 17:10:14567 server_ssl_config_ = used_ssl_config;
[email protected]8e6441ca2010-08-19 05:56:38568 response_.cert_request_info = cert_info;
[email protected]65a3b912010-08-21 05:46:58569 OnIOComplete(ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]8e6441ca2010-08-19 05:56:38570}
571
[email protected]511f6f52010-12-17 03:58:29572void HttpNetworkTransaction::OnHttpsProxyTunnelResponse(
573 const HttpResponseInfo& response_info,
[email protected]102e27c2011-02-23 01:01:31574 const SSLConfig& used_ssl_config,
575 const ProxyInfo& used_proxy_info,
[email protected]92b9a3e2012-11-09 08:52:52576 HttpStreamBase* stream) {
[email protected]511f6f52010-12-17 03:58:29577 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_);
578
579 headers_valid_ = true;
580 response_ = response_info;
[email protected]102957f2011-09-02 17:10:14581 server_ssl_config_ = used_ssl_config;
[email protected]102e27c2011-02-23 01:01:31582 proxy_info_ = used_proxy_info;
[email protected]b8015c42013-12-24 15:18:19583 if (stream_)
584 total_received_bytes_ += stream_->GetTotalReceivedBytes();
[email protected]511f6f52010-12-17 03:58:29585 stream_.reset(stream);
586 stream_request_.reset(); // we're done with the stream request
587 OnIOComplete(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
588}
589
[email protected]8e6441ca2010-08-19 05:56:38590bool HttpNetworkTransaction::is_https_request() const {
591 return request_->url.SchemeIs("https");
initial.commit586acc5fe2008-07-26 22:42:52592}
593
initial.commit586acc5fe2008-07-26 22:42:52594void HttpNetworkTransaction::DoCallback(int rv) {
[email protected]0b0bf032010-09-21 18:08:50595 DCHECK_NE(rv, ERR_IO_PENDING);
[email protected]49639fa2011-12-20 23:22:41596 DCHECK(!callback_.is_null());
initial.commit586acc5fe2008-07-26 22:42:52597
[email protected]96d570e42008-08-05 22:43:04598 // Since Run may result in Read being called, clear user_callback_ up front.
[email protected]49639fa2011-12-20 23:22:41599 CompletionCallback c = callback_;
600 callback_.Reset();
601 c.Run(rv);
initial.commit586acc5fe2008-07-26 22:42:52602}
603
604void HttpNetworkTransaction::OnIOComplete(int result) {
605 int rv = DoLoop(result);
606 if (rv != ERR_IO_PENDING)
607 DoCallback(rv);
608}
609
610int HttpNetworkTransaction::DoLoop(int result) {
611 DCHECK(next_state_ != STATE_NONE);
612
613 int rv = result;
614 do {
615 State state = next_state_;
616 next_state_ = STATE_NONE;
617 switch (state) {
[email protected]1826a402014-01-08 15:40:48618 case STATE_NOTIFY_BEFORE_CREATE_STREAM:
619 DCHECK_EQ(OK, rv);
620 rv = DoNotifyBeforeCreateStream();
621 break;
[email protected]82918cc2010-08-25 17:24:50622 case STATE_CREATE_STREAM:
623 DCHECK_EQ(OK, rv);
624 rv = DoCreateStream();
625 break;
626 case STATE_CREATE_STREAM_COMPLETE:
627 rv = DoCreateStreamComplete(rv);
628 break;
[email protected]351ab642010-08-05 16:55:31629 case STATE_INIT_STREAM:
630 DCHECK_EQ(OK, rv);
631 rv = DoInitStream();
632 break;
633 case STATE_INIT_STREAM_COMPLETE:
634 rv = DoInitStreamComplete(rv);
635 break;
[email protected]044de0642010-06-17 10:42:15636 case STATE_GENERATE_PROXY_AUTH_TOKEN:
637 DCHECK_EQ(OK, rv);
638 rv = DoGenerateProxyAuthToken();
639 break;
640 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE:
641 rv = DoGenerateProxyAuthTokenComplete(rv);
642 break;
643 case STATE_GENERATE_SERVER_AUTH_TOKEN:
644 DCHECK_EQ(OK, rv);
645 rv = DoGenerateServerAuthToken();
646 break;
647 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE:
648 rv = DoGenerateServerAuthTokenComplete(rv);
649 break;
[email protected]daddea62012-09-19 05:51:13650 case STATE_INIT_REQUEST_BODY:
651 DCHECK_EQ(OK, rv);
652 rv = DoInitRequestBody();
653 break;
654 case STATE_INIT_REQUEST_BODY_COMPLETE:
655 rv = DoInitRequestBodyComplete(rv);
656 break;
[email protected]4875ba12011-03-30 22:31:51657 case STATE_BUILD_REQUEST:
[email protected]725355a2009-03-25 20:42:55658 DCHECK_EQ(OK, rv);
[email protected]b6754252012-06-13 23:14:38659 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST);
[email protected]4875ba12011-03-30 22:31:51660 rv = DoBuildRequest();
661 break;
662 case STATE_BUILD_REQUEST_COMPLETE:
663 rv = DoBuildRequestComplete(rv);
664 break;
665 case STATE_SEND_REQUEST:
666 DCHECK_EQ(OK, rv);
[email protected]0877e3d2009-10-17 22:29:57667 rv = DoSendRequest();
initial.commit586acc5fe2008-07-26 22:42:52668 break;
[email protected]0877e3d2009-10-17 22:29:57669 case STATE_SEND_REQUEST_COMPLETE:
670 rv = DoSendRequestComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43671 net_log_.EndEventWithNetErrorCode(
672 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, rv);
initial.commit586acc5fe2008-07-26 22:42:52673 break;
674 case STATE_READ_HEADERS:
[email protected]725355a2009-03-25 20:42:55675 DCHECK_EQ(OK, rv);
[email protected]b6754252012-06-13 23:14:38676 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS);
initial.commit586acc5fe2008-07-26 22:42:52677 rv = DoReadHeaders();
678 break;
679 case STATE_READ_HEADERS_COMPLETE:
680 rv = DoReadHeadersComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43681 net_log_.EndEventWithNetErrorCode(
682 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, rv);
initial.commit586acc5fe2008-07-26 22:42:52683 break;
684 case STATE_READ_BODY:
[email protected]725355a2009-03-25 20:42:55685 DCHECK_EQ(OK, rv);
[email protected]b6754252012-06-13 23:14:38686 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_BODY);
initial.commit586acc5fe2008-07-26 22:42:52687 rv = DoReadBody();
688 break;
689 case STATE_READ_BODY_COMPLETE:
690 rv = DoReadBodyComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43691 net_log_.EndEventWithNetErrorCode(
692 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, rv);
initial.commit586acc5fe2008-07-26 22:42:52693 break;
[email protected]2d2697f92009-02-18 21:00:32694 case STATE_DRAIN_BODY_FOR_AUTH_RESTART:
[email protected]725355a2009-03-25 20:42:55695 DCHECK_EQ(OK, rv);
[email protected]9e743cd2010-03-16 07:03:53696 net_log_.BeginEvent(
[email protected]b6754252012-06-13 23:14:38697 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART);
[email protected]2d2697f92009-02-18 21:00:32698 rv = DoDrainBodyForAuthRestart();
699 break;
700 case STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE:
701 rv = DoDrainBodyForAuthRestartComplete(rv);
[email protected]d7fd1782011-02-08 19:16:43702 net_log_.EndEventWithNetErrorCode(
703 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, rv);
[email protected]2d2697f92009-02-18 21:00:32704 break;
initial.commit586acc5fe2008-07-26 22:42:52705 default:
706 NOTREACHED() << "bad state";
707 rv = ERR_FAILED;
[email protected]96d570e42008-08-05 22:43:04708 break;
initial.commit586acc5fe2008-07-26 22:42:52709 }
710 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
711
712 return rv;
713}
714
[email protected]1826a402014-01-08 15:40:48715int HttpNetworkTransaction::DoNotifyBeforeCreateStream() {
716 next_state_ = STATE_CREATE_STREAM;
717 bool defer = false;
718 if (!before_network_start_callback_.is_null())
719 before_network_start_callback_.Run(&defer);
720 if (!defer)
721 return OK;
722 return ERR_IO_PENDING;
723}
724
[email protected]82918cc2010-08-25 17:24:50725int HttpNetworkTransaction::DoCreateStream() {
726 next_state_ = STATE_CREATE_STREAM_COMPLETE;
[email protected]831e4a32013-11-14 02:14:44727 if (ForWebSocketHandshake()) {
728 stream_request_.reset(
[email protected]0191b51c2013-11-18 10:55:23729 session_->http_stream_factory_for_websocket()
[email protected]831e4a32013-11-14 02:14:44730 ->RequestWebSocketHandshakeStream(
731 *request_,
732 priority_,
733 server_ssl_config_,
734 proxy_ssl_config_,
735 this,
736 websocket_handshake_stream_base_create_helper_,
737 net_log_));
738 } else {
739 stream_request_.reset(
740 session_->http_stream_factory()->RequestStream(
741 *request_,
742 priority_,
743 server_ssl_config_,
744 proxy_ssl_config_,
745 this,
746 net_log_));
747 }
[email protected]26816882010-10-14 18:03:09748 DCHECK(stream_request_.get());
[email protected]8e6441ca2010-08-19 05:56:38749 return ERR_IO_PENDING;
[email protected]351ab642010-08-05 16:55:31750}
751
[email protected]82918cc2010-08-25 17:24:50752int HttpNetworkTransaction::DoCreateStreamComplete(int result) {
[email protected]394816e92010-08-03 07:38:59753 if (result == OK) {
[email protected]82918cc2010-08-25 17:24:50754 next_state_ = STATE_INIT_STREAM;
[email protected]8e6441ca2010-08-19 05:56:38755 DCHECK(stream_.get());
[email protected]adb00242010-10-29 03:04:33756 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
757 result = HandleCertificateRequest(result);
[email protected]511f6f52010-12-17 03:58:29758 } else if (result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) {
759 // Return OK and let the caller read the proxy's error page
760 next_state_ = STATE_NONE;
761 return OK;
[email protected]394816e92010-08-03 07:38:59762 }
763
[email protected]bd0b6772011-01-11 19:59:30764 // Handle possible handshake errors that may have occurred if the stream
765 // used SSL for one or more of the layers.
766 result = HandleSSLHandshakeError(result);
767
[email protected]8e6441ca2010-08-19 05:56:38768 // At this point we are done with the stream_request_.
[email protected]26816882010-10-14 18:03:09769 stream_request_.reset();
[email protected]8e6441ca2010-08-19 05:56:38770 return result;
[email protected]394816e92010-08-03 07:38:59771}
772
[email protected]82918cc2010-08-25 17:24:50773int HttpNetworkTransaction::DoInitStream() {
774 DCHECK(stream_.get());
775 next_state_ = STATE_INIT_STREAM_COMPLETE;
[email protected]262eec82013-03-19 21:01:36776 return stream_->InitializeStream(request_, priority_, net_log_, io_callback_);
[email protected]82918cc2010-08-25 17:24:50777}
778
779int HttpNetworkTransaction::DoInitStreamComplete(int result) {
780 if (result == OK) {
781 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN;
[email protected]82918cc2010-08-25 17:24:50782 } else {
[email protected]82918cc2010-08-25 17:24:50783 if (result < 0)
[email protected]044dcc52010-09-17 15:44:26784 result = HandleIOError(result);
785
786 // The stream initialization failed, so this stream will never be useful.
[email protected]b8015c42013-12-24 15:18:19787 if (stream_)
788 total_received_bytes_ += stream_->GetTotalReceivedBytes();
[email protected]044dcc52010-09-17 15:44:26789 stream_.reset();
[email protected]82918cc2010-08-25 17:24:50790 }
791
792 return result;
793}
794
[email protected]044de0642010-06-17 10:42:15795int HttpNetworkTransaction::DoGenerateProxyAuthToken() {
796 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE;
797 if (!ShouldApplyProxyAuth())
798 return OK;
[email protected]394816e92010-08-03 07:38:59799 HttpAuth::Target target = HttpAuth::AUTH_PROXY;
800 if (!auth_controllers_[target].get())
[email protected]3598c6022010-09-17 23:13:09801 auth_controllers_[target] =
802 new HttpAuthController(target,
803 AuthURL(target),
[email protected]102e27c2011-02-23 01:01:31804 session_->http_auth_cache(),
[email protected]3598c6022010-09-17 23:13:09805 session_->http_auth_handler_factory());
[email protected]394816e92010-08-03 07:38:59806 return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
[email protected]49639fa2011-12-20 23:22:41807 io_callback_,
[email protected]394816e92010-08-03 07:38:59808 net_log_);
[email protected]044de0642010-06-17 10:42:15809}
810
811int HttpNetworkTransaction::DoGenerateProxyAuthTokenComplete(int rv) {
812 DCHECK_NE(ERR_IO_PENDING, rv);
813 if (rv == OK)
814 next_state_ = STATE_GENERATE_SERVER_AUTH_TOKEN;
815 return rv;
816}
817
818int HttpNetworkTransaction::DoGenerateServerAuthToken() {
819 next_state_ = STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE;
[email protected]394816e92010-08-03 07:38:59820 HttpAuth::Target target = HttpAuth::AUTH_SERVER;
[email protected]2217aa22013-10-11 03:03:54821 if (!auth_controllers_[target].get()) {
[email protected]3598c6022010-09-17 23:13:09822 auth_controllers_[target] =
823 new HttpAuthController(target,
824 AuthURL(target),
[email protected]102e27c2011-02-23 01:01:31825 session_->http_auth_cache(),
[email protected]3598c6022010-09-17 23:13:09826 session_->http_auth_handler_factory());
[email protected]2217aa22013-10-11 03:03:54827 if (request_->load_flags & LOAD_DO_NOT_USE_EMBEDDED_IDENTITY)
828 auth_controllers_[target]->DisableEmbeddedIdentity();
829 }
[email protected]044de0642010-06-17 10:42:15830 if (!ShouldApplyServerAuth())
831 return OK;
[email protected]394816e92010-08-03 07:38:59832 return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
[email protected]49639fa2011-12-20 23:22:41833 io_callback_,
[email protected]394816e92010-08-03 07:38:59834 net_log_);
[email protected]044de0642010-06-17 10:42:15835}
836
837int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) {
838 DCHECK_NE(ERR_IO_PENDING, rv);
839 if (rv == OK)
[email protected]daddea62012-09-19 05:51:13840 next_state_ = STATE_INIT_REQUEST_BODY;
[email protected]044de0642010-06-17 10:42:15841 return rv;
842}
843
[email protected]2979a492011-04-06 00:29:14844void HttpNetworkTransaction::BuildRequestHeaders(bool using_proxy) {
845 request_headers_.SetHeader(HttpRequestHeaders::kHost,
846 GetHostAndOptionalPort(request_->url));
847
848 // For compat with HTTP/1.0 servers and proxies:
849 if (using_proxy) {
850 request_headers_.SetHeader(HttpRequestHeaders::kProxyConnection,
851 "keep-alive");
852 } else {
853 request_headers_.SetHeader(HttpRequestHeaders::kConnection, "keep-alive");
854 }
855
[email protected]2979a492011-04-06 00:29:14856 // Add a content length header?
[email protected]bf3eb002012-11-15 05:50:11857 if (request_->upload_data_stream) {
858 if (request_->upload_data_stream->is_chunked()) {
[email protected]2979a492011-04-06 00:29:14859 request_headers_.SetHeader(
860 HttpRequestHeaders::kTransferEncoding, "chunked");
861 } else {
862 request_headers_.SetHeader(
863 HttpRequestHeaders::kContentLength,
[email protected]bf3eb002012-11-15 05:50:11864 base::Uint64ToString(request_->upload_data_stream->size()));
[email protected]2979a492011-04-06 00:29:14865 }
866 } else if (request_->method == "POST" || request_->method == "PUT" ||
867 request_->method == "HEAD") {
868 // An empty POST/PUT request still needs a content length. As for HEAD,
869 // IE and Safari also add a content length header. Presumably it is to
870 // support sending a HEAD request to an URL that only expects to be sent a
871 // POST or some other method that normally would have a message body.
872 request_headers_.SetHeader(HttpRequestHeaders::kContentLength, "0");
873 }
874
875 // Honor load flags that impact proxy caches.
876 if (request_->load_flags & LOAD_BYPASS_CACHE) {
877 request_headers_.SetHeader(HttpRequestHeaders::kPragma, "no-cache");
878 request_headers_.SetHeader(HttpRequestHeaders::kCacheControl, "no-cache");
879 } else if (request_->load_flags & LOAD_VALIDATE_CACHE) {
880 request_headers_.SetHeader(HttpRequestHeaders::kCacheControl, "max-age=0");
881 }
882
883 if (ShouldApplyProxyAuth() && HaveAuth(HttpAuth::AUTH_PROXY))
884 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader(
885 &request_headers_);
886 if (ShouldApplyServerAuth() && HaveAuth(HttpAuth::AUTH_SERVER))
887 auth_controllers_[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader(
888 &request_headers_);
889
[email protected]c10450102011-06-27 09:06:16890 request_headers_.MergeFrom(request_->extra_headers);
[email protected]1252d42f2014-07-01 21:20:20891
892 if (using_proxy && !before_proxy_headers_sent_callback_.is_null())
893 before_proxy_headers_sent_callback_.Run(proxy_info_, &request_headers_);
894
[email protected]173f8e22013-04-10 04:18:20895 response_.did_use_http_auth =
896 request_headers_.HasHeader(HttpRequestHeaders::kAuthorization) ||
897 request_headers_.HasHeader(HttpRequestHeaders::kProxyAuthorization);
[email protected]2979a492011-04-06 00:29:14898}
899
[email protected]daddea62012-09-19 05:51:13900int HttpNetworkTransaction::DoInitRequestBody() {
901 next_state_ = STATE_INIT_REQUEST_BODY_COMPLETE;
[email protected]daddea62012-09-19 05:51:13902 int rv = OK;
[email protected]bf3eb002012-11-15 05:50:11903 if (request_->upload_data_stream)
904 rv = request_->upload_data_stream->Init(io_callback_);
[email protected]daddea62012-09-19 05:51:13905 return rv;
906}
[email protected]4875ba12011-03-30 22:31:51907
[email protected]daddea62012-09-19 05:51:13908int HttpNetworkTransaction::DoInitRequestBodyComplete(int result) {
909 if (result == OK)
910 next_state_ = STATE_BUILD_REQUEST;
[email protected]daddea62012-09-19 05:51:13911 return result;
912}
913
914int HttpNetworkTransaction::DoBuildRequest() {
915 next_state_ = STATE_BUILD_REQUEST_COMPLETE;
[email protected]4875ba12011-03-30 22:31:51916 headers_valid_ = false;
917
918 // This is constructed lazily (instead of within our Start method), so that
919 // we have proxy info available.
920 if (request_headers_.IsEmpty()) {
921 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
922 !is_https_request();
[email protected]2979a492011-04-06 00:29:14923 BuildRequestHeaders(using_proxy);
[email protected]4875ba12011-03-30 22:31:51924 }
925
[email protected]4875ba12011-03-30 22:31:51926 return OK;
927}
928
929int HttpNetworkTransaction::DoBuildRequestComplete(int result) {
[email protected]9f489d72011-04-04 23:29:24930 if (result == OK)
931 next_state_ = STATE_SEND_REQUEST;
[email protected]4875ba12011-03-30 22:31:51932 return result;
933}
934
[email protected]0877e3d2009-10-17 22:29:57935int HttpNetworkTransaction::DoSendRequest() {
[email protected]58e32bb2013-01-21 18:23:25936 send_start_time_ = base::TimeTicks::Now();
[email protected]0877e3d2009-10-17 22:29:57937 next_state_ = STATE_SEND_REQUEST_COMPLETE;
938
[email protected]bf3eb002012-11-15 05:50:11939 return stream_->SendRequest(request_headers_, &response_, io_callback_);
initial.commit586acc5fe2008-07-26 22:42:52940}
941
[email protected]0877e3d2009-10-17 22:29:57942int HttpNetworkTransaction::DoSendRequestComplete(int result) {
[email protected]58e32bb2013-01-21 18:23:25943 send_end_time_ = base::TimeTicks::Now();
initial.commit586acc5fe2008-07-26 22:42:52944 if (result < 0)
945 return HandleIOError(result);
[email protected]7cf7ccb2013-04-20 02:53:08946 response_.network_accessed = true;
[email protected]0877e3d2009-10-17 22:29:57947 next_state_ = STATE_READ_HEADERS;
initial.commit586acc5fe2008-07-26 22:42:52948 return OK;
949}
950
951int HttpNetworkTransaction::DoReadHeaders() {
952 next_state_ = STATE_READ_HEADERS_COMPLETE;
[email protected]49639fa2011-12-20 23:22:41953 return stream_->ReadResponseHeaders(io_callback_);
initial.commit586acc5fe2008-07-26 22:42:52954}
955
956int HttpNetworkTransaction::DoReadHeadersComplete(int result) {
[email protected]0b45559b2009-06-12 21:45:11957 // We can get a certificate error or ERR_SSL_CLIENT_AUTH_CERT_NEEDED here
958 // due to SSL renegotiation.
[email protected]8e6441ca2010-08-19 05:56:38959 if (IsCertificateError(result)) {
960 // We don't handle a certificate error during SSL renegotiation, so we
961 // have to return an error that's not in the certificate error range
962 // (-2xx).
963 LOG(ERROR) << "Got a server certificate with error " << result
964 << " during SSL renegotiation";
965 result = ERR_CERT_ERROR_IN_SSL_RENEGOTIATION;
966 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
967 // TODO(wtc): Need a test case for this code path!
968 DCHECK(stream_.get());
969 DCHECK(is_https_request());
970 response_.cert_request_info = new SSLCertRequestInfo;
[email protected]90499482013-06-01 00:39:50971 stream_->GetSSLCertRequestInfo(response_.cert_request_info.get());
[email protected]8e6441ca2010-08-19 05:56:38972 result = HandleCertificateRequest(result);
973 if (result == OK)
974 return result;
[email protected]2181ea002009-06-09 01:37:27975 }
976
[email protected]4d283b32013-10-17 12:57:27977 if (result == ERR_QUIC_HANDSHAKE_FAILED) {
978 ResetConnectionAndRequestForResend();
979 return OK;
980 }
981
[email protected]0877e3d2009-10-17 22:29:57982 // After we call RestartWithAuth a new response_time will be recorded, and
983 // we need to be cautious about incorrectly logging the duration across the
984 // authentication activity.
[email protected]8e6441ca2010-08-19 05:56:38985 if (result == OK)
986 LogTransactionConnectedMetrics();
initial.commit586acc5fe2008-07-26 22:42:52987
[email protected]c871864d72014-03-13 19:56:19988 // ERR_CONNECTION_CLOSED is treated differently at this point; if partial
989 // response headers were received, we do the best we can to make sense of it
990 // and send it back up the stack.
991 //
992 // TODO(davidben): Consider moving this to HttpBasicStream, It's a little
993 // bizarre for SPDY. Assuming this logic is useful at all.
994 // TODO(davidben): Bubble the error code up so we do not cache?
995 if (result == ERR_CONNECTION_CLOSED && response_.headers.get())
996 result = OK;
997
998 if (result < 0)
999 return HandleIOError(result);
1000
[email protected]90499482013-06-01 00:39:501001 DCHECK(response_.headers.get());
initial.commit586acc5fe2008-07-26 22:42:521002
[email protected]d58ceea82014-06-04 10:55:541003 // On a 408 response from the server ("Request Timeout") on a stale socket,
1004 // retry the request.
[email protected]0aff0d82014-06-14 08:49:041005 // Headers can be NULL because of http://crbug.com/384554.
1006 if (response_.headers.get() && response_.headers->response_code() == 408 &&
[email protected]d58ceea82014-06-04 10:55:541007 stream_->IsConnectionReused()) {
1008 net_log_.AddEventWithNetErrorCode(
1009 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR,
1010 response_.headers->response_code());
1011 // This will close the socket - it would be weird to try and reuse it, even
1012 // if the server doesn't actually close it.
1013 ResetConnectionAndRequestForResend();
1014 return OK;
1015 }
1016
[email protected]93f8b562012-03-27 01:00:161017 // Like Net.HttpResponseCode, but only for MAIN_FRAME loads.
1018 if (request_->load_flags & LOAD_MAIN_FRAME) {
1019 const int response_code = response_.headers->response_code();
1020 UMA_HISTOGRAM_ENUMERATION(
1021 "Net.HttpResponseCode_Nxx_MainFrame", response_code/100, 10);
1022 }
1023
[email protected]3abacd62012-06-10 20:20:321024 net_log_.AddEvent(
1025 NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
1026 base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers));
[email protected]dbb83db2010-05-11 18:13:391027
[email protected]a7e41312009-12-16 23:18:141028 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) {
[email protected]0877e3d2009-10-17 22:29:571029 // HTTP/0.9 doesn't support the PUT method, so lack of response headers
1030 // indicates a buggy server. See:
1031 // https://bugzilla.mozilla.org/show_bug.cgi?id=193921
1032 if (request_->method == "PUT")
1033 return ERR_METHOD_NOT_SUPPORTED;
1034 }
[email protected]4ddaf2502008-10-23 18:26:191035
[email protected]0877e3d2009-10-17 22:29:571036 // Check for an intermediate 100 Continue response. An origin server is
1037 // allowed to send this response even if we didn't ask for it, so we just
1038 // need to skip over it.
1039 // We treat any other 1xx in this same way (although in practice getting
1040 // a 1xx that isn't a 100 is rare).
[email protected]831e4a32013-11-14 02:14:441041 // Unless this is a WebSocket request, in which case we pass it on up.
1042 if (response_.headers->response_code() / 100 == 1 &&
1043 !ForWebSocketHandshake()) {
[email protected]007b3f82013-04-09 08:46:451044 response_.headers = new HttpResponseHeaders(std::string());
[email protected]0877e3d2009-10-17 22:29:571045 next_state_ = STATE_READ_HEADERS;
1046 return OK;
1047 }
1048
[email protected]8e6441ca2010-08-19 05:56:381049 HostPortPair endpoint = HostPortPair(request_->url.HostNoBrackets(),
1050 request_->url.EffectiveIntPort());
[email protected]d7599122014-05-24 03:37:231051 ProcessAlternateProtocol(session_,
[email protected]90499482013-06-01 00:39:501052 *response_.headers.get(),
[email protected]8e6441ca2010-08-19 05:56:381053 endpoint);
[email protected]564b4912010-03-09 16:30:421054
[email protected]e772db3f2010-07-12 18:11:131055 int rv = HandleAuthChallenge();
[email protected]0877e3d2009-10-17 22:29:571056 if (rv != OK)
1057 return rv;
1058
[email protected]8536ef52010-09-30 16:18:211059 if (is_https_request())
1060 stream_->GetSSLInfo(&response_.ssl_info);
1061
[email protected]0877e3d2009-10-17 22:29:571062 headers_valid_ = true;
[email protected]e00bfd572014-04-30 08:06:431063
1064 if (session_->huffman_aggregator()) {
1065 session_->huffman_aggregator()->AggregateTransactionCharacterCounts(
1066 *request_,
1067 request_headers_,
1068 proxy_info_.proxy_server(),
1069 *response_.headers);
1070 }
[email protected]0877e3d2009-10-17 22:29:571071 return OK;
initial.commit586acc5fe2008-07-26 22:42:521072}
1073
1074int HttpNetworkTransaction::DoReadBody() {
[email protected]90499482013-06-01 00:39:501075 DCHECK(read_buf_.get());
[email protected]6501bc02009-06-25 20:55:131076 DCHECK_GT(read_buf_len_, 0);
[email protected]8e6441ca2010-08-19 05:56:381077 DCHECK(stream_ != NULL);
initial.commit586acc5fe2008-07-26 22:42:521078
1079 next_state_ = STATE_READ_BODY_COMPLETE;
[email protected]90499482013-06-01 00:39:501080 return stream_->ReadResponseBody(
1081 read_buf_.get(), read_buf_len_, io_callback_);
initial.commit586acc5fe2008-07-26 22:42:521082}
1083
1084int HttpNetworkTransaction::DoReadBodyComplete(int result) {
1085 // We are done with the Read call.
[email protected]8e6441ca2010-08-19 05:56:381086 bool done = false;
1087 if (result <= 0) {
1088 DCHECK_NE(ERR_IO_PENDING, result);
initial.commit586acc5fe2008-07-26 22:42:521089 done = true;
[email protected]8e6441ca2010-08-19 05:56:381090 }
[email protected]9492e4a2010-02-24 00:58:461091
[email protected]8e6441ca2010-08-19 05:56:381092 bool keep_alive = false;
[email protected]351ab642010-08-05 16:55:311093 if (stream_->IsResponseBodyComplete()) {
[email protected]8e6441ca2010-08-19 05:56:381094 // Note: Just because IsResponseBodyComplete is true, we're not
1095 // necessarily "done". We're only "done" when it is the last
1096 // read on this HttpNetworkTransaction, which will be signified
1097 // by a zero-length read.
1098 // TODO(mbelshe): The keepalive property is really a property of
1099 // the stream. No need to compute it here just to pass back
1100 // to the stream's Close function.
[email protected]5c6908e2012-08-06 18:53:471101 // TODO(rtenneti): CanFindEndOfResponse should return false if there are no
1102 // ResponseHeaders.
1103 if (stream_->CanFindEndOfResponse()) {
1104 HttpResponseHeaders* headers = GetResponseHeaders();
1105 if (headers)
1106 keep_alive = headers->IsKeepAlive();
1107 }
initial.commit586acc5fe2008-07-26 22:42:521108 }
1109
[email protected]8e6441ca2010-08-19 05:56:381110 // Clean up connection if we are done.
initial.commit586acc5fe2008-07-26 22:42:521111 if (done) {
[email protected]56300172008-11-06 18:42:551112 LogTransactionMetrics();
[email protected]8e6441ca2010-08-19 05:56:381113 stream_->Close(!keep_alive);
[email protected]e2a915a2010-08-19 07:55:011114 // Note: we don't reset the stream here. We've closed it, but we still
1115 // need it around so that callers can call methods such as
1116 // GetUploadProgress() and have them be meaningful.
1117 // TODO(mbelshe): This means we closed the stream here, and we close it
1118 // again in ~HttpNetworkTransaction. Clean that up.
1119
[email protected]8e6441ca2010-08-19 05:56:381120 // The next Read call will return 0 (EOF).
initial.commit586acc5fe2008-07-26 22:42:521121 }
1122
1123 // Clear these to avoid leaving around old state.
1124 read_buf_ = NULL;
1125 read_buf_len_ = 0;
1126
1127 return result;
1128}
1129
[email protected]2d2697f92009-02-18 21:00:321130int HttpNetworkTransaction::DoDrainBodyForAuthRestart() {
1131 // This method differs from DoReadBody only in the next_state_. So we just
1132 // call DoReadBody and override the next_state_. Perhaps there is a more
1133 // elegant way for these two methods to share code.
1134 int rv = DoReadBody();
1135 DCHECK(next_state_ == STATE_READ_BODY_COMPLETE);
1136 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE;
1137 return rv;
1138}
1139
[email protected]0877e3d2009-10-17 22:29:571140// TODO(wtc): This method and the DoReadBodyComplete method are almost
1141// the same. Figure out a good way for these two methods to share code.
[email protected]2d2697f92009-02-18 21:00:321142int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) {
[email protected]68873ba2009-06-04 21:49:231143 // keep_alive defaults to true because the very reason we're draining the
1144 // response body is to reuse the connection for auth restart.
1145 bool done = false, keep_alive = true;
[email protected]2d2697f92009-02-18 21:00:321146 if (result < 0) {
[email protected]0877e3d2009-10-17 22:29:571147 // Error or closed connection while reading the socket.
[email protected]2d2697f92009-02-18 21:00:321148 done = true;
[email protected]68873ba2009-06-04 21:49:231149 keep_alive = false;
[email protected]351ab642010-08-05 16:55:311150 } else if (stream_->IsResponseBodyComplete()) {
[email protected]0877e3d2009-10-17 22:29:571151 done = true;
[email protected]2d2697f92009-02-18 21:00:321152 }
1153
1154 if (done) {
1155 DidDrainBodyForAuthRestart(keep_alive);
1156 } else {
1157 // Keep draining.
1158 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART;
1159 }
1160
1161 return OK;
1162}
1163
[email protected]8e3d2d32010-06-13 18:46:231164void HttpNetworkTransaction::LogTransactionConnectedMetrics() {
1165 if (logged_response_time_)
1166 return;
1167
1168 logged_response_time_ = true;
1169
[email protected]a7e41312009-12-16 23:18:141170 base::TimeDelta total_duration = response_.response_time - start_time_;
[email protected]9a0a55f2009-04-13 23:23:031171
[email protected]d6b55392011-08-05 04:04:351172 UMA_HISTOGRAM_CUSTOM_TIMES(
1173 "Net.Transaction_Connected",
[email protected]510e854f2009-04-20 18:39:081174 total_duration,
[email protected]9a0a55f2009-04-13 23:23:031175 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10),
1176 100);
[email protected]1fa47592009-07-27 22:45:001177
[email protected]c38ec5a2010-08-25 23:32:381178 bool reused_socket = stream_->IsConnectionReused();
1179 if (!reused_socket) {
[email protected]d6b55392011-08-05 04:04:351180 UMA_HISTOGRAM_CUSTOM_TIMES(
1181 "Net.Transaction_Connected_New_b",
[email protected]b01998a2009-04-21 01:01:111182 total_duration,
1183 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10),
1184 100);
[email protected]0310d432009-08-25 07:49:521185 }
1186
[email protected]31ae7ab2012-04-24 21:09:051187 // Currently, non-HIGHEST priority requests are frame or sub-frame resource
[email protected]510e854f2009-04-20 18:39:081188 // types. This will change when we also prioritize certain subresources like
1189 // css, js, etc.
[email protected]262eec82013-03-19 21:01:361190 if (priority_ != HIGHEST) {
[email protected]d6b55392011-08-05 04:04:351191 UMA_HISTOGRAM_CUSTOM_TIMES(
1192 "Net.Priority_High_Latency_b",
[email protected]510e854f2009-04-20 18:39:081193 total_duration,
1194 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10),
1195 100);
1196 } else {
[email protected]d6b55392011-08-05 04:04:351197 UMA_HISTOGRAM_CUSTOM_TIMES(
1198 "Net.Priority_Low_Latency_b",
[email protected]510e854f2009-04-20 18:39:081199 total_duration,
1200 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10),
1201 100);
1202 }
[email protected]9a0a55f2009-04-13 23:23:031203}
1204
[email protected]56300172008-11-06 18:42:551205void HttpNetworkTransaction::LogTransactionMetrics() const {
[email protected]0877e3d2009-10-17 22:29:571206 base::TimeDelta duration = base::Time::Now() -
[email protected]2227c692010-05-04 15:36:111207 response_.request_time;
[email protected]56300172008-11-06 18:42:551208 if (60 < duration.InMinutes())
1209 return;
[email protected]0b48db42009-03-23 02:45:111210
[email protected]21b316a2009-03-23 18:25:061211 base::TimeDelta total_duration = base::Time::Now() - start_time_;
1212
[email protected]d6b55392011-08-05 04:04:351213 UMA_HISTOGRAM_CUSTOM_TIMES("Net.Transaction_Latency_b", duration,
1214 base::TimeDelta::FromMilliseconds(1),
1215 base::TimeDelta::FromMinutes(10),
1216 100);
1217 UMA_HISTOGRAM_CUSTOM_TIMES("Net.Transaction_Latency_Total",
1218 total_duration,
1219 base::TimeDelta::FromMilliseconds(1),
1220 base::TimeDelta::FromMinutes(10), 100);
[email protected]5c68d692011-08-24 04:59:411221
[email protected]c38ec5a2010-08-25 23:32:381222 if (!stream_->IsConnectionReused()) {
[email protected]d6b55392011-08-05 04:04:351223 UMA_HISTOGRAM_CUSTOM_TIMES(
1224 "Net.Transaction_Latency_Total_New_Connection",
[email protected]808f6402009-03-30 20:02:071225 total_duration, base::TimeDelta::FromMilliseconds(1),
1226 base::TimeDelta::FromMinutes(10), 100);
1227 }
[email protected]56300172008-11-06 18:42:551228}
1229
[email protected]5e363962009-06-19 19:57:011230int HttpNetworkTransaction::HandleCertificateRequest(int error) {
[email protected]8e6441ca2010-08-19 05:56:381231 // There are two paths through which the server can request a certificate
1232 // from us. The first is during the initial handshake, the second is
1233 // during SSL renegotiation.
1234 //
1235 // In both cases, we want to close the connection before proceeding.
1236 // We do this for two reasons:
1237 // First, we don't want to keep the connection to the server hung for a
1238 // long time while the user selects a certificate.
1239 // Second, even if we did keep the connection open, NSS has a bug where
1240 // restarting the handshake for ClientAuth is currently broken.
[email protected]65a3b912010-08-21 05:46:581241 DCHECK_EQ(error, ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]8e6441ca2010-08-19 05:56:381242
1243 if (stream_.get()) {
1244 // Since we already have a stream, we're being called as part of SSL
1245 // renegotiation.
1246 DCHECK(!stream_request_.get());
[email protected]b8015c42013-12-24 15:18:191247 total_received_bytes_ += stream_->GetTotalReceivedBytes();
[email protected]8e6441ca2010-08-19 05:56:381248 stream_->Close(true);
1249 stream_.reset();
1250 }
1251
[email protected]26816882010-10-14 18:03:091252 // The server is asking for a client certificate during the initial
1253 // handshake.
1254 stream_request_.reset();
[email protected]5e363962009-06-19 19:57:011255
[email protected]ec229bc92010-11-22 09:51:451256 // If the user selected one of the certificates in client_certs or declined
1257 // to provide one for this server before, use the past decision
1258 // automatically.
1259 scoped_refptr<X509Certificate> client_cert;
1260 bool found_cached_cert = session_->ssl_client_auth_cache()->Lookup(
1261 response_.cert_request_info->host_and_port, &client_cert);
1262 if (!found_cached_cert)
1263 return error;
1264
1265 // Check that the certificate selected is still a certificate the server
1266 // is likely to accept, based on the criteria supplied in the
1267 // CertificateRequest message.
[email protected]90499482013-06-01 00:39:501268 if (client_cert.get()) {
[email protected]f1958c382013-02-07 00:15:261269 const std::vector<std::string>& cert_authorities =
1270 response_.cert_request_info->cert_authorities;
[email protected]ec229bc92010-11-22 09:51:451271
[email protected]f1958c382013-02-07 00:15:261272 bool cert_still_valid = cert_authorities.empty() ||
1273 client_cert->IsIssuedByEncoded(cert_authorities);
[email protected]ec229bc92010-11-22 09:51:451274 if (!cert_still_valid)
1275 return error;
[email protected]5e363962009-06-19 19:57:011276 }
[email protected]ec229bc92010-11-22 09:51:451277
1278 // TODO(davidben): Add a unit test which covers this path; we need to be
1279 // able to send a legitimate certificate and also bypass/clear the
1280 // SSL session cache.
[email protected]102957f2011-09-02 17:10:141281 SSLConfig* ssl_config = response_.cert_request_info->is_proxy ?
1282 &proxy_ssl_config_ : &server_ssl_config_;
1283 ssl_config->send_client_cert = true;
1284 ssl_config->client_cert = client_cert;
[email protected]ec229bc92010-11-22 09:51:451285 next_state_ = STATE_CREATE_STREAM;
1286 // Reset the other member variables.
1287 // Note: this is necessary only with SSL renegotiation.
1288 ResetStateForRestart();
1289 return OK;
[email protected]0b45559b2009-06-12 21:45:111290}
1291
[email protected]384cc73a2013-12-08 22:41:031292void HttpNetworkTransaction::HandleClientAuthError(int error) {
1293 if (server_ssl_config_.send_client_cert &&
1294 (error == ERR_SSL_PROTOCOL_ERROR || IsClientCertificateError(error))) {
1295 session_->ssl_client_auth_cache()->Remove(
[email protected]791879c2013-12-17 07:22:411296 HostPortPair::FromURL(request_->url));
[email protected]384cc73a2013-12-08 22:41:031297 }
1298}
1299
[email protected]bd0b6772011-01-11 19:59:301300// TODO(rch): This does not correctly handle errors when an SSL proxy is
1301// being used, as all of the errors are handled as if they were generated
1302// by the endpoint host, request_->url, rather than considering if they were
[email protected]1c53a1f2011-01-13 00:36:381303// generated by the SSL proxy. http://crbug.com/69329
[email protected]bd0b6772011-01-11 19:59:301304int HttpNetworkTransaction::HandleSSLHandshakeError(int error) {
1305 DCHECK(request_);
[email protected]384cc73a2013-12-08 22:41:031306 HandleClientAuthError(error);
[email protected]bd0b6772011-01-11 19:59:301307
[email protected]02d1d442013-08-10 13:38:261308 bool should_fallback = false;
[email protected]158ac972013-04-19 23:29:231309 uint16 version_max = server_ssl_config_.version_max;
1310
initial.commit586acc5fe2008-07-26 22:42:521311 switch (error) {
[email protected]12833302014-07-02 01:57:311312 case ERR_CONNECTION_CLOSED:
[email protected]bd0b6772011-01-11 19:59:301313 case ERR_SSL_PROTOCOL_ERROR:
1314 case ERR_SSL_VERSION_OR_CIPHER_MISMATCH:
[email protected]158ac972013-04-19 23:29:231315 if (version_max >= SSL_PROTOCOL_VERSION_TLS1 &&
1316 version_max > server_ssl_config_.version_min) {
[email protected]80c75f682012-05-26 16:22:171317 // This could be a TLS-intolerant server or a server that chose a
1318 // cipher suite defined only for higher protocol versions (such as
1319 // an SSL 3.0 server that chose a TLS-only cipher suite). Fall
1320 // back to the next lower version and retry.
1321 // NOTE: if the SSLClientSocket class doesn't support TLS 1.1,
1322 // specifying TLS 1.1 in version_max will result in a TLS 1.0
1323 // handshake, so falling back from TLS 1.1 to TLS 1.0 will simply
1324 // repeat the TLS 1.0 handshake. To avoid this problem, the default
1325 // version_max should match the maximum protocol version supported
1326 // by the SSLClientSocket class.
[email protected]158ac972013-04-19 23:29:231327 version_max--;
[email protected]c57ec022013-11-25 21:30:511328
1329 // Fallback to the lower SSL version.
1330 // While SSL 3.0 fallback should be eliminated because of security
1331 // reasons, there is a high risk of breaking the servers if this is
1332 // done in general.
[email protected]001e547e2013-12-06 16:08:391333 should_fallback = true;
[email protected]1c773ea12009-04-28 19:58:421334 }
initial.commit586acc5fe2008-07-26 22:42:521335 break;
[email protected]12833302014-07-02 01:57:311336 case ERR_CONNECTION_RESET:
1337 if (version_max >= SSL_PROTOCOL_VERSION_TLS1_1 &&
1338 version_max > server_ssl_config_.version_min) {
1339 // Some network devices that inspect application-layer packets seem to
1340 // inject TCP reset packets to break the connections when they see TLS
1341 // 1.1 in ClientHello or ServerHello. See http://crbug.com/130293.
1342 //
1343 // Only allow ERR_CONNECTION_RESET to trigger a fallback from TLS 1.1 or
1344 // 1.2. We don't lose much in this fallback because the explicit IV for
1345 // CBC mode in TLS 1.1 is approximated by record splitting in TLS
1346 // 1.0. The fallback will be more painful for TLS 1.2 when we have GCM
1347 // support.
1348 //
1349 // ERR_CONNECTION_RESET is a common network error, so we don't want it
1350 // to trigger a version fallback in general, especially the TLS 1.0 ->
1351 // SSL 3.0 fallback, which would drop TLS extensions.
1352 version_max--;
1353 should_fallback = true;
1354 }
1355 break;
[email protected]02d1d442013-08-10 13:38:261356 case ERR_SSL_BAD_RECORD_MAC_ALERT:
1357 if (version_max >= SSL_PROTOCOL_VERSION_TLS1_1 &&
1358 version_max > server_ssl_config_.version_min) {
1359 // Some broken SSL devices negotiate TLS 1.0 when sent a TLS 1.1 or
1360 // 1.2 ClientHello, but then return a bad_record_mac alert. See
1361 // crbug.com/260358. In order to make the fallback as minimal as
1362 // possible, this fallback is only triggered for >= TLS 1.1.
1363 version_max--;
1364 should_fallback = true;
1365 }
1366 break;
[email protected]a53e4d12013-12-07 16:37:241367 case ERR_SSL_INAPPROPRIATE_FALLBACK:
1368 // The server told us that we should not have fallen back. A buggy server
1369 // could trigger ERR_SSL_INAPPROPRIATE_FALLBACK with the initial
1370 // connection. |fallback_error_code_| is initialised to
1371 // ERR_SSL_INAPPROPRIATE_FALLBACK to catch this case.
1372 error = fallback_error_code_;
1373 break;
[email protected]02d1d442013-08-10 13:38:261374 }
1375
1376 if (should_fallback) {
1377 net_log_.AddEvent(
1378 NetLog::TYPE_SSL_VERSION_FALLBACK,
1379 base::Bind(&NetLogSSLVersionFallbackCallback,
1380 &request_->url, error, server_ssl_config_.version_max,
1381 version_max));
[email protected]a53e4d12013-12-07 16:37:241382 fallback_error_code_ = error;
[email protected]02d1d442013-08-10 13:38:261383 server_ssl_config_.version_max = version_max;
1384 server_ssl_config_.version_fallback = true;
1385 ResetConnectionAndRequestForResend();
1386 error = OK;
initial.commit586acc5fe2008-07-26 22:42:521387 }
[email protected]158ac972013-04-19 23:29:231388
initial.commit586acc5fe2008-07-26 22:42:521389 return error;
1390}
1391
[email protected]bd0b6772011-01-11 19:59:301392// This method determines whether it is safe to resend the request after an
1393// IO error. It can only be called in response to request header or body
1394// write errors or response header read errors. It should not be used in
1395// other cases, such as a Connect error.
1396int HttpNetworkTransaction::HandleIOError(int error) {
[email protected]384cc73a2013-12-08 22:41:031397 // Because the peer may request renegotiation with client authentication at
1398 // any time, check and handle client authentication errors.
1399 HandleClientAuthError(error);
[email protected]bd0b6772011-01-11 19:59:301400
1401 switch (error) {
1402 // If we try to reuse a connection that the server is in the process of
1403 // closing, we may end up successfully writing out our request (or a
1404 // portion of our request) only to find a connection error when we try to
1405 // read from (or finish writing to) the socket.
1406 case ERR_CONNECTION_RESET:
1407 case ERR_CONNECTION_CLOSED:
1408 case ERR_CONNECTION_ABORTED:
[email protected]202965992011-12-07 23:04:511409 // There can be a race between the socket pool checking checking whether a
1410 // socket is still connected, receiving the FIN, and sending/reading data
1411 // on a reused socket. If we receive the FIN between the connectedness
1412 // check and writing/reading from the socket, we may first learn the socket
1413 // is disconnected when we get a ERR_SOCKET_NOT_CONNECTED. This will most
1414 // likely happen when trying to retrieve its IP address.
1415 // See http://crbug.com/105824 for more details.
1416 case ERR_SOCKET_NOT_CONNECTED:
[email protected]a34f61ee2014-03-18 20:59:491417 // If a socket is closed on its initial request, HttpStreamParser returns
1418 // ERR_EMPTY_RESPONSE. This may still be close/reuse race if the socket was
1419 // preconnected but failed to be used before the server timed it out.
1420 case ERR_EMPTY_RESPONSE:
1421 if (ShouldResendRequest()) {
[email protected]b6754252012-06-13 23:14:381422 net_log_.AddEventWithNetErrorCode(
1423 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
[email protected]bd0b6772011-01-11 19:59:301424 ResetConnectionAndRequestForResend();
1425 error = OK;
1426 }
1427 break;
[email protected]8753a122011-10-16 08:05:081428 case ERR_SPDY_PING_FAILED:
[email protected]721c0ce2011-10-13 02:41:001429 case ERR_SPDY_SERVER_REFUSED_STREAM:
[email protected]4d283b32013-10-17 12:57:271430 case ERR_QUIC_HANDSHAKE_FAILED:
[email protected]b6754252012-06-13 23:14:381431 net_log_.AddEventWithNetErrorCode(
1432 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
[email protected]721c0ce2011-10-13 02:41:001433 ResetConnectionAndRequestForResend();
1434 error = OK;
1435 break;
[email protected]bd0b6772011-01-11 19:59:301436 }
1437 return error;
1438}
1439
[email protected]c3b35c22008-09-27 03:19:421440void HttpNetworkTransaction::ResetStateForRestart() {
[email protected]697ef4c2010-10-14 16:38:581441 ResetStateForAuthRestart();
[email protected]b8015c42013-12-24 15:18:191442 if (stream_)
1443 total_received_bytes_ += stream_->GetTotalReceivedBytes();
[email protected]697ef4c2010-10-14 16:38:581444 stream_.reset();
1445}
1446
1447void HttpNetworkTransaction::ResetStateForAuthRestart() {
[email protected]58e32bb2013-01-21 18:23:251448 send_start_time_ = base::TimeTicks();
1449 send_end_time_ = base::TimeTicks();
[email protected]58e32bb2013-01-21 18:23:251450
[email protected]0757e7702009-03-27 04:00:221451 pending_auth_target_ = HttpAuth::AUTH_NONE;
[email protected]c3b35c22008-09-27 03:19:421452 read_buf_ = NULL;
1453 read_buf_len_ = 0;
[email protected]0877e3d2009-10-17 22:29:571454 headers_valid_ = false;
[email protected]b94f92d2010-10-27 16:45:201455 request_headers_.Clear();
[email protected]a7e41312009-12-16 23:18:141456 response_ = HttpResponseInfo();
[email protected]8e6441ca2010-08-19 05:56:381457 establishing_tunnel_ = false;
[email protected]0877e3d2009-10-17 22:29:571458}
1459
1460HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const {
[email protected]90499482013-06-01 00:39:501461 return response_.headers.get();
[email protected]c3b35c22008-09-27 03:19:421462}
1463
[email protected]a34f61ee2014-03-18 20:59:491464bool HttpNetworkTransaction::ShouldResendRequest() const {
[email protected]8e6441ca2010-08-19 05:56:381465 bool connection_is_proven = stream_->IsConnectionReused();
1466 bool has_received_headers = GetResponseHeaders() != NULL;
[email protected]58cebf8f2010-07-31 19:20:161467
[email protected]2a5c76b2008-09-25 22:15:161468 // NOTE: we resend a request only if we reused a keep-alive connection.
1469 // This automatically prevents an infinite resend loop because we'll run
1470 // out of the cached keep-alive connections eventually.
[email protected]8e6441ca2010-08-19 05:56:381471 if (connection_is_proven && !has_received_headers)
1472 return true;
1473 return false;
[email protected]1c773ea12009-04-28 19:58:421474}
1475
1476void HttpNetworkTransaction::ResetConnectionAndRequestForResend() {
[email protected]8e6441ca2010-08-19 05:56:381477 if (stream_.get()) {
1478 stream_->Close(true);
1479 stream_.reset();
[email protected]58cebf8f2010-07-31 19:20:161480 }
1481
[email protected]0877e3d2009-10-17 22:29:571482 // We need to clear request_headers_ because it contains the real request
1483 // headers, but we may need to resend the CONNECT request first to recreate
1484 // the SSL tunnel.
[email protected]b94f92d2010-10-27 16:45:201485 request_headers_.Clear();
[email protected]82918cc2010-08-25 17:24:501486 next_state_ = STATE_CREATE_STREAM; // Resend the request.
[email protected]86ec30d2008-09-29 21:53:541487}
1488
[email protected]1c773ea12009-04-28 19:58:421489bool HttpNetworkTransaction::ShouldApplyProxyAuth() const {
[email protected]2df19bb2010-08-25 20:13:461490 return !is_https_request() &&
1491 (proxy_info_.is_https() || proxy_info_.is_http());
[email protected]1c773ea12009-04-28 19:58:421492}
license.botbf09a502008-08-24 00:55:551493
[email protected]1c773ea12009-04-28 19:58:421494bool HttpNetworkTransaction::ShouldApplyServerAuth() const {
[email protected]8a1f3312010-05-25 19:25:041495 return !(request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA);
[email protected]1c773ea12009-04-28 19:58:421496}
1497
[email protected]e772db3f2010-07-12 18:11:131498int HttpNetworkTransaction::HandleAuthChallenge() {
[email protected]ad8e04a2010-11-01 04:16:271499 scoped_refptr<HttpResponseHeaders> headers(GetResponseHeaders());
[email protected]90499482013-06-01 00:39:501500 DCHECK(headers.get());
[email protected]c3b35c22008-09-27 03:19:421501
[email protected]0877e3d2009-10-17 22:29:571502 int status = headers->response_code();
[email protected]9094b602012-02-27 21:44:581503 if (status != HTTP_UNAUTHORIZED &&
1504 status != HTTP_PROXY_AUTHENTICATION_REQUIRED)
[email protected]c3b35c22008-09-27 03:19:421505 return OK;
[email protected]9094b602012-02-27 21:44:581506 HttpAuth::Target target = status == HTTP_PROXY_AUTHENTICATION_REQUIRED ?
[email protected]2227c692010-05-04 15:36:111507 HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER;
[email protected]038e9a32008-10-08 22:40:161508 if (target == HttpAuth::AUTH_PROXY && proxy_info_.is_direct())
1509 return ERR_UNEXPECTED_PROXY_AUTH;
[email protected]c3b35c22008-09-27 03:19:421510
[email protected]9094b602012-02-27 21:44:581511 // This case can trigger when an HTTPS server responds with a "Proxy
1512 // authentication required" status code through a non-authenticating
1513 // proxy.
[email protected]7a67a8152010-11-05 18:31:101514 if (!auth_controllers_[target].get())
1515 return ERR_UNEXPECTED_PROXY_AUTH;
1516
[email protected]a7ea8832010-07-12 17:54:541517 int rv = auth_controllers_[target]->HandleAuthChallenge(
[email protected]560c0432010-07-13 20:45:311518 headers, (request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA) != 0, false,
1519 net_log_);
[email protected]228404f2010-06-24 04:31:411520 if (auth_controllers_[target]->HaveAuthHandler())
1521 pending_auth_target_ = target;
1522
1523 scoped_refptr<AuthChallengeInfo> auth_info =
1524 auth_controllers_[target]->auth_info();
1525 if (auth_info.get())
1526 response_.auth_challenge = auth_info;
1527
[email protected]228404f2010-06-24 04:31:411528 return rv;
[email protected]f9ee6b52008-11-08 06:46:231529}
1530
[email protected]8e6441ca2010-08-19 05:56:381531bool HttpNetworkTransaction::HaveAuth(HttpAuth::Target target) const {
1532 return auth_controllers_[target].get() &&
1533 auth_controllers_[target]->HaveAuth();
1534}
1535
[email protected]228404f2010-06-24 04:31:411536GURL HttpNetworkTransaction::AuthURL(HttpAuth::Target target) const {
1537 switch (target) {
[email protected]2df19bb2010-08-25 20:13:461538 case HttpAuth::AUTH_PROXY: {
[email protected]228404f2010-06-24 04:31:411539 if (!proxy_info_.proxy_server().is_valid() ||
1540 proxy_info_.proxy_server().is_direct()) {
1541 return GURL(); // There is no proxy server.
1542 }
[email protected]2df19bb2010-08-25 20:13:461543 const char* scheme = proxy_info_.is_https() ? "https://" : "http://";
1544 return GURL(scheme +
[email protected]2fbaecf22010-07-22 22:20:351545 proxy_info_.proxy_server().host_port_pair().ToString());
[email protected]2df19bb2010-08-25 20:13:461546 }
[email protected]228404f2010-06-24 04:31:411547 case HttpAuth::AUTH_SERVER:
1548 return request_->url;
1549 default:
1550 return GURL();
1551 }
[email protected]c3b35c22008-09-27 03:19:421552}
1553
[email protected]831e4a32013-11-14 02:14:441554bool HttpNetworkTransaction::ForWebSocketHandshake() const {
[email protected]23d3e022013-11-23 20:38:141555 return websocket_handshake_stream_base_create_helper_ &&
1556 request_->url.SchemeIsWSOrWSS();
[email protected]831e4a32013-11-14 02:14:441557}
1558
[email protected]d8eb84242010-09-25 02:25:061559#define STATE_CASE(s) \
1560 case s: \
1561 description = base::StringPrintf("%s (0x%08X)", #s, s); \
1562 break
[email protected]aef04272010-06-28 18:03:041563
1564std::string HttpNetworkTransaction::DescribeState(State state) {
1565 std::string description;
1566 switch (state) {
[email protected]1826a402014-01-08 15:40:481567 STATE_CASE(STATE_NOTIFY_BEFORE_CREATE_STREAM);
[email protected]82918cc2010-08-25 17:24:501568 STATE_CASE(STATE_CREATE_STREAM);
1569 STATE_CASE(STATE_CREATE_STREAM_COMPLETE);
[email protected]daddea62012-09-19 05:51:131570 STATE_CASE(STATE_INIT_REQUEST_BODY);
1571 STATE_CASE(STATE_INIT_REQUEST_BODY_COMPLETE);
[email protected]4875ba12011-03-30 22:31:511572 STATE_CASE(STATE_BUILD_REQUEST);
1573 STATE_CASE(STATE_BUILD_REQUEST_COMPLETE);
[email protected]aef04272010-06-28 18:03:041574 STATE_CASE(STATE_SEND_REQUEST);
1575 STATE_CASE(STATE_SEND_REQUEST_COMPLETE);
1576 STATE_CASE(STATE_READ_HEADERS);
1577 STATE_CASE(STATE_READ_HEADERS_COMPLETE);
[email protected]aef04272010-06-28 18:03:041578 STATE_CASE(STATE_READ_BODY);
1579 STATE_CASE(STATE_READ_BODY_COMPLETE);
1580 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART);
1581 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE);
[email protected]aef04272010-06-28 18:03:041582 STATE_CASE(STATE_NONE);
1583 default:
[email protected]d8eb84242010-09-25 02:25:061584 description = base::StringPrintf("Unknown state 0x%08X (%u)", state,
1585 state);
[email protected]aef04272010-06-28 18:03:041586 break;
1587 }
1588 return description;
1589}
1590
1591#undef STATE_CASE
1592
[email protected]c3b35c22008-09-27 03:19:421593} // namespace net