OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 session_(session), | 142 session_(session), |
143 request_(NULL), | 143 request_(NULL), |
144 priority_(priority), | 144 priority_(priority), |
145 headers_valid_(false), | 145 headers_valid_(false), |
146 server_ssl_failure_state_(SSL_FAILURE_NONE), | 146 server_ssl_failure_state_(SSL_FAILURE_NONE), |
147 fallback_error_code_(ERR_SSL_INAPPROPRIATE_FALLBACK), | 147 fallback_error_code_(ERR_SSL_INAPPROPRIATE_FALLBACK), |
148 fallback_failure_state_(SSL_FAILURE_NONE), | 148 fallback_failure_state_(SSL_FAILURE_NONE), |
149 request_headers_(), | 149 request_headers_(), |
150 read_buf_len_(0), | 150 read_buf_len_(0), |
151 total_received_bytes_(0), | 151 total_received_bytes_(0), |
| 152 total_sent_bytes_(0), |
152 next_state_(STATE_NONE), | 153 next_state_(STATE_NONE), |
153 establishing_tunnel_(false), | 154 establishing_tunnel_(false), |
154 websocket_handshake_stream_base_create_helper_(NULL) { | 155 websocket_handshake_stream_base_create_helper_(NULL) { |
155 session->ssl_config_service()->GetSSLConfig(&server_ssl_config_); | 156 session->ssl_config_service()->GetSSLConfig(&server_ssl_config_); |
156 session->GetNextProtos(&server_ssl_config_.next_protos); | 157 session->GetNextProtos(&server_ssl_config_.next_protos); |
157 proxy_ssl_config_ = server_ssl_config_; | 158 proxy_ssl_config_ = server_ssl_config_; |
158 } | 159 } |
159 | 160 |
160 HttpNetworkTransaction::~HttpNetworkTransaction() { | 161 HttpNetworkTransaction::~HttpNetworkTransaction() { |
161 if (stream_.get()) { | 162 if (stream_.get()) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 // We don't need to drain the response body, so we act as if we had drained | 299 // We don't need to drain the response body, so we act as if we had drained |
299 // the response body. | 300 // the response body. |
300 DidDrainBodyForAuthRestart(keep_alive); | 301 DidDrainBodyForAuthRestart(keep_alive); |
301 } | 302 } |
302 | 303 |
303 void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { | 304 void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { |
304 DCHECK(!stream_request_.get()); | 305 DCHECK(!stream_request_.get()); |
305 | 306 |
306 if (stream_.get()) { | 307 if (stream_.get()) { |
307 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 308 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
| 309 total_sent_bytes_ += stream_->GetTotalSentBytes(); |
308 HttpStream* new_stream = NULL; | 310 HttpStream* new_stream = NULL; |
309 if (keep_alive && stream_->CanReuseConnection()) { | 311 if (keep_alive && stream_->CanReuseConnection()) { |
310 // We should call connection_->set_idle_time(), but this doesn't occur | 312 // We should call connection_->set_idle_time(), but this doesn't occur |
311 // often enough to be worth the trouble. | 313 // often enough to be worth the trouble. |
312 stream_->SetConnectionReused(); | 314 stream_->SetConnectionReused(); |
313 new_stream = stream_->RenewStreamForAuth(); | 315 new_stream = stream_->RenewStreamForAuth(); |
314 } | 316 } |
315 | 317 |
316 if (!new_stream) { | 318 if (!new_stream) { |
317 // Close the stream and mark it as not_reusable. Even in the | 319 // Close the stream and mark it as not_reusable. Even in the |
318 // keep_alive case, we've determined that the stream_ is not | 320 // keep_alive case, we've determined that the stream_ is not |
319 // reusable if new_stream is NULL. | 321 // reusable if new_stream is NULL. |
320 stream_->Close(true); | 322 stream_->Close(true); |
321 next_state_ = STATE_CREATE_STREAM; | 323 next_state_ = STATE_CREATE_STREAM; |
322 } else { | 324 } else { |
323 // Renewed streams shouldn't carry over received bytes. | 325 // Renewed streams shouldn't carry over sent or received bytes. |
324 DCHECK_EQ(0, new_stream->GetTotalReceivedBytes()); | 326 DCHECK_EQ(0, new_stream->GetTotalReceivedBytes()); |
| 327 DCHECK_EQ(0, new_stream->GetTotalSentBytes()); |
325 next_state_ = STATE_INIT_STREAM; | 328 next_state_ = STATE_INIT_STREAM; |
326 } | 329 } |
327 stream_.reset(new_stream); | 330 stream_.reset(new_stream); |
328 } | 331 } |
329 | 332 |
330 // Reset the other member variables. | 333 // Reset the other member variables. |
331 ResetStateForAuthRestart(); | 334 ResetStateForAuthRestart(); |
332 } | 335 } |
333 | 336 |
334 bool HttpNetworkTransaction::IsReadyToRestartForAuth() { | 337 bool HttpNetworkTransaction::IsReadyToRestartForAuth() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return true; | 387 return true; |
385 } | 388 } |
386 | 389 |
387 int64 HttpNetworkTransaction::GetTotalReceivedBytes() const { | 390 int64 HttpNetworkTransaction::GetTotalReceivedBytes() const { |
388 int64 total_received_bytes = total_received_bytes_; | 391 int64 total_received_bytes = total_received_bytes_; |
389 if (stream_) | 392 if (stream_) |
390 total_received_bytes += stream_->GetTotalReceivedBytes(); | 393 total_received_bytes += stream_->GetTotalReceivedBytes(); |
391 return total_received_bytes; | 394 return total_received_bytes; |
392 } | 395 } |
393 | 396 |
| 397 int64_t HttpNetworkTransaction::GetTotalSentBytes() const { |
| 398 int64_t total_sent_bytes = total_sent_bytes_; |
| 399 if (stream_) |
| 400 total_sent_bytes += stream_->GetTotalSentBytes(); |
| 401 return total_sent_bytes; |
| 402 } |
| 403 |
394 void HttpNetworkTransaction::DoneReading() {} | 404 void HttpNetworkTransaction::DoneReading() {} |
395 | 405 |
396 const HttpResponseInfo* HttpNetworkTransaction::GetResponseInfo() const { | 406 const HttpResponseInfo* HttpNetworkTransaction::GetResponseInfo() const { |
397 return &response_; | 407 return &response_; |
398 } | 408 } |
399 | 409 |
400 LoadState HttpNetworkTransaction::GetLoadState() const { | 410 LoadState HttpNetworkTransaction::GetLoadState() const { |
401 // TODO(wtc): Define a new LoadState value for the | 411 // TODO(wtc): Define a new LoadState value for the |
402 // STATE_INIT_CONNECTION_COMPLETE state, which delays the HTTP request. | 412 // STATE_INIT_CONNECTION_COMPLETE state, which delays the HTTP request. |
403 switch (next_state_) { | 413 switch (next_state_) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 DCHECK_EQ(next_state_, STATE_CREATE_STREAM); | 478 DCHECK_EQ(next_state_, STATE_CREATE_STREAM); |
469 return DoLoop(OK); | 479 return DoLoop(OK); |
470 } | 480 } |
471 | 481 |
472 void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config, | 482 void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config, |
473 const ProxyInfo& used_proxy_info, | 483 const ProxyInfo& used_proxy_info, |
474 HttpStream* stream) { | 484 HttpStream* stream) { |
475 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 485 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
476 DCHECK(stream_request_.get()); | 486 DCHECK(stream_request_.get()); |
477 | 487 |
478 if (stream_) | 488 if (stream_) { |
479 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 489 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
| 490 total_sent_bytes_ += stream_->GetTotalSentBytes(); |
| 491 } |
480 stream_.reset(stream); | 492 stream_.reset(stream); |
481 server_ssl_config_ = used_ssl_config; | 493 server_ssl_config_ = used_ssl_config; |
482 proxy_info_ = used_proxy_info; | 494 proxy_info_ = used_proxy_info; |
483 response_.was_npn_negotiated = stream_request_->was_npn_negotiated(); | 495 response_.was_npn_negotiated = stream_request_->was_npn_negotiated(); |
484 response_.npn_negotiated_protocol = SSLClientSocket::NextProtoToString( | 496 response_.npn_negotiated_protocol = SSLClientSocket::NextProtoToString( |
485 stream_request_->protocol_negotiated()); | 497 stream_request_->protocol_negotiated()); |
486 response_.was_fetched_via_spdy = stream_request_->using_spdy(); | 498 response_.was_fetched_via_spdy = stream_request_->using_spdy(); |
487 response_.was_fetched_via_proxy = !proxy_info_.is_direct(); | 499 response_.was_fetched_via_proxy = !proxy_info_.is_direct(); |
488 if (response_.was_fetched_via_proxy && !proxy_info_.is_empty()) | 500 if (response_.was_fetched_via_proxy && !proxy_info_.is_empty()) |
489 response_.proxy_server = proxy_info_.proxy_server().host_port_pair(); | 501 response_.proxy_server = proxy_info_.proxy_server().host_port_pair(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 const ProxyInfo& used_proxy_info, | 580 const ProxyInfo& used_proxy_info, |
569 HttpStream* stream) { | 581 HttpStream* stream) { |
570 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 582 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
571 | 583 |
572 CopyConnectionAttemptsFromStreamRequest(); | 584 CopyConnectionAttemptsFromStreamRequest(); |
573 | 585 |
574 headers_valid_ = true; | 586 headers_valid_ = true; |
575 response_ = response_info; | 587 response_ = response_info; |
576 server_ssl_config_ = used_ssl_config; | 588 server_ssl_config_ = used_ssl_config; |
577 proxy_info_ = used_proxy_info; | 589 proxy_info_ = used_proxy_info; |
578 if (stream_) | 590 if (stream_) { |
579 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 591 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
| 592 total_sent_bytes_ += stream_->GetTotalSentBytes(); |
| 593 } |
580 stream_.reset(stream); | 594 stream_.reset(stream); |
581 stream_request_.reset(); // we're done with the stream request | 595 stream_request_.reset(); // we're done with the stream request |
582 OnIOComplete(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); | 596 OnIOComplete(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); |
583 } | 597 } |
584 | 598 |
585 void HttpNetworkTransaction::GetConnectionAttempts( | 599 void HttpNetworkTransaction::GetConnectionAttempts( |
586 ConnectionAttempts* out) const { | 600 ConnectionAttempts* out) const { |
587 *out = connection_attempts_; | 601 *out = connection_attempts_; |
588 } | 602 } |
589 | 603 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 } | 817 } |
804 | 818 |
805 int HttpNetworkTransaction::DoInitStreamComplete(int result) { | 819 int HttpNetworkTransaction::DoInitStreamComplete(int result) { |
806 if (result == OK) { | 820 if (result == OK) { |
807 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; | 821 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; |
808 } else { | 822 } else { |
809 if (result < 0) | 823 if (result < 0) |
810 result = HandleIOError(result); | 824 result = HandleIOError(result); |
811 | 825 |
812 // The stream initialization failed, so this stream will never be useful. | 826 // The stream initialization failed, so this stream will never be useful. |
813 if (stream_) | 827 if (stream_) { |
814 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 828 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
| 829 total_sent_bytes_ += stream_->GetTotalSentBytes(); |
| 830 } |
815 stream_.reset(); | 831 stream_.reset(); |
816 } | 832 } |
817 | 833 |
818 return result; | 834 return result; |
819 } | 835 } |
820 | 836 |
821 int HttpNetworkTransaction::DoGenerateProxyAuthToken() { | 837 int HttpNetworkTransaction::DoGenerateProxyAuthToken() { |
822 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE; | 838 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE; |
823 if (!ShouldApplyProxyAuth()) | 839 if (!ShouldApplyProxyAuth()) |
824 return OK; | 840 return OK; |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 // long time while the user selects a certificate. | 1194 // long time while the user selects a certificate. |
1179 // Second, even if we did keep the connection open, NSS has a bug where | 1195 // Second, even if we did keep the connection open, NSS has a bug where |
1180 // restarting the handshake for ClientAuth is currently broken. | 1196 // restarting the handshake for ClientAuth is currently broken. |
1181 DCHECK_EQ(error, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | 1197 DCHECK_EQ(error, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
1182 | 1198 |
1183 if (stream_.get()) { | 1199 if (stream_.get()) { |
1184 // Since we already have a stream, we're being called as part of SSL | 1200 // Since we already have a stream, we're being called as part of SSL |
1185 // renegotiation. | 1201 // renegotiation. |
1186 DCHECK(!stream_request_.get()); | 1202 DCHECK(!stream_request_.get()); |
1187 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 1203 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
| 1204 total_sent_bytes_ += stream_->GetTotalSentBytes(); |
1188 stream_->Close(true); | 1205 stream_->Close(true); |
1189 stream_.reset(); | 1206 stream_.reset(); |
1190 } | 1207 } |
1191 | 1208 |
1192 // The server is asking for a client certificate during the initial | 1209 // The server is asking for a client certificate during the initial |
1193 // handshake. | 1210 // handshake. |
1194 stream_request_.reset(); | 1211 stream_request_.reset(); |
1195 | 1212 |
1196 // If the user selected one of the certificates in client_certs or declined | 1213 // If the user selected one of the certificates in client_certs or declined |
1197 // to provide one for this server before, use the past decision | 1214 // to provide one for this server before, use the past decision |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1401 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error); | 1418 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error); |
1402 ResetConnectionAndRequestForResend(); | 1419 ResetConnectionAndRequestForResend(); |
1403 error = OK; | 1420 error = OK; |
1404 break; | 1421 break; |
1405 } | 1422 } |
1406 return error; | 1423 return error; |
1407 } | 1424 } |
1408 | 1425 |
1409 void HttpNetworkTransaction::ResetStateForRestart() { | 1426 void HttpNetworkTransaction::ResetStateForRestart() { |
1410 ResetStateForAuthRestart(); | 1427 ResetStateForAuthRestart(); |
1411 if (stream_) | 1428 if (stream_) { |
1412 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 1429 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
| 1430 total_sent_bytes_ += stream_->GetTotalSentBytes(); |
| 1431 } |
1413 stream_.reset(); | 1432 stream_.reset(); |
1414 } | 1433 } |
1415 | 1434 |
1416 void HttpNetworkTransaction::ResetStateForAuthRestart() { | 1435 void HttpNetworkTransaction::ResetStateForAuthRestart() { |
1417 send_start_time_ = base::TimeTicks(); | 1436 send_start_time_ = base::TimeTicks(); |
1418 send_end_time_ = base::TimeTicks(); | 1437 send_end_time_ = base::TimeTicks(); |
1419 | 1438 |
1420 pending_auth_target_ = HttpAuth::AUTH_NONE; | 1439 pending_auth_target_ = HttpAuth::AUTH_NONE; |
1421 read_buf_ = NULL; | 1440 read_buf_ = NULL; |
1422 read_buf_len_ = 0; | 1441 read_buf_len_ = 0; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 DCHECK(stream_request_); | 1660 DCHECK(stream_request_); |
1642 | 1661 |
1643 // Since the transaction can restart with auth credentials, it may create a | 1662 // Since the transaction can restart with auth credentials, it may create a |
1644 // stream more than once. Accumulate all of the connection attempts across | 1663 // stream more than once. Accumulate all of the connection attempts across |
1645 // those streams by appending them to the vector: | 1664 // those streams by appending them to the vector: |
1646 for (const auto& attempt : stream_request_->connection_attempts()) | 1665 for (const auto& attempt : stream_request_->connection_attempts()) |
1647 connection_attempts_.push_back(attempt); | 1666 connection_attempts_.push_back(attempt); |
1648 } | 1667 } |
1649 | 1668 |
1650 } // namespace net | 1669 } // namespace net |
OLD | NEW |