| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return rv; | 291 return rv; |
| 292 } | 292 } |
| 293 | 293 |
| 294 int HttpNetworkTransaction::RestartIgnoringLastError( | 294 int HttpNetworkTransaction::RestartIgnoringLastError( |
| 295 CompletionCallback* callback) { | 295 CompletionCallback* callback) { |
| 296 if (connection_->socket() && connection_->socket()->IsConnectedAndIdle()) { | 296 if (connection_->socket() && connection_->socket()->IsConnectedAndIdle()) { |
| 297 // TODO(wtc): Should we update any of the connection histograms that we | 297 // TODO(wtc): Should we update any of the connection histograms that we |
| 298 // update in DoSSLConnectComplete if |result| is OK? | 298 // update in DoSSLConnectComplete if |result| is OK? |
| 299 if (using_spdy_) { | 299 if (using_spdy_) { |
| 300 // TODO(cbentzel): Add auth support to spdy. See http://crbug.com/46620 | 300 // TODO(cbentzel): Add auth support to spdy. See http://crbug.com/46620 |
| 301 next_state_ = STATE_INIT_STREAM; | 301 next_state_ = STATE_SPDY_GET_STREAM; |
| 302 } else { | 302 } else { |
| 303 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; | 303 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; |
| 304 } | 304 } |
| 305 } else { | 305 } else { |
| 306 if (connection_->socket()) | 306 if (connection_->socket()) |
| 307 connection_->socket()->Disconnect(); | 307 connection_->socket()->Disconnect(); |
| 308 connection_->Reset(); | 308 connection_->Reset(); |
| 309 next_state_ = STATE_INIT_CONNECTION; | 309 next_state_ = STATE_INIT_CONNECTION; |
| 310 } | 310 } |
| 311 int rv = DoLoop(OK); | 311 int rv = DoLoop(OK); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 return rv; | 363 return rv; |
| 364 } | 364 } |
| 365 | 365 |
| 366 void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) { | 366 void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) { |
| 367 DCHECK(HaveAuth(target)); | 367 DCHECK(HaveAuth(target)); |
| 368 DCHECK(!establishing_tunnel_); | 368 DCHECK(!establishing_tunnel_); |
| 369 bool keep_alive = false; | 369 bool keep_alive = false; |
| 370 // Even if the server says the connection is keep-alive, we have to be | 370 // Even if the server says the connection is keep-alive, we have to be |
| 371 // able to find the end of each response in order to reuse the connection. | 371 // able to find the end of each response in order to reuse the connection. |
| 372 if (GetResponseHeaders()->IsKeepAlive() && | 372 if (GetResponseHeaders()->IsKeepAlive() && |
| 373 stream_->CanFindEndOfResponse()) { | 373 http_stream_->CanFindEndOfResponse()) { |
| 374 // If the response body hasn't been completely read, we need to drain | 374 // If the response body hasn't been completely read, we need to drain |
| 375 // it first. | 375 // it first. |
| 376 if (!stream_->IsResponseBodyComplete()) { | 376 if (!http_stream_->IsResponseBodyComplete()) { |
| 377 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; | 377 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; |
| 378 read_buf_ = new IOBuffer(kDrainBodyBufferSize); // A bit bucket. | 378 read_buf_ = new IOBuffer(kDrainBodyBufferSize); // A bit bucket. |
| 379 read_buf_len_ = kDrainBodyBufferSize; | 379 read_buf_len_ = kDrainBodyBufferSize; |
| 380 return; | 380 return; |
| 381 } | 381 } |
| 382 keep_alive = true; | 382 keep_alive = true; |
| 383 } | 383 } |
| 384 | 384 |
| 385 // We don't need to drain the response body, so we act as if we had drained | 385 // We don't need to drain the response body, so we act as if we had drained |
| 386 // the response body. | 386 // the response body. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // See http://crbug.com/8473. | 423 // See http://crbug.com/8473. |
| 424 DCHECK(proxy_info_.is_http()); | 424 DCHECK(proxy_info_.is_http()); |
| 425 DCHECK_EQ(headers->response_code(), 407); | 425 DCHECK_EQ(headers->response_code(), 407); |
| 426 LOG(WARNING) << "Blocked proxy response with status " | 426 LOG(WARNING) << "Blocked proxy response with status " |
| 427 << headers->response_code() << " to CONNECT request for " | 427 << headers->response_code() << " to CONNECT request for " |
| 428 << GetHostAndPort(request_->url) << "."; | 428 << GetHostAndPort(request_->url) << "."; |
| 429 return ERR_TUNNEL_CONNECTION_FAILED; | 429 return ERR_TUNNEL_CONNECTION_FAILED; |
| 430 } | 430 } |
| 431 | 431 |
| 432 // Are we using SPDY or HTTP? | 432 // Are we using SPDY or HTTP? |
| 433 next_state = STATE_READ_BODY; | 433 if (using_spdy_) { |
| 434 DCHECK(stream_->GetResponseInfo()->headers); | 434 DCHECK(!http_stream_.get()); |
| 435 if (!using_spdy_ && !connection_->is_initialized()) { | 435 DCHECK(spdy_http_stream_->GetResponseInfo()->headers); |
| 436 return 0; // |*connection_| has been reset. Treat like EOF. | 436 next_state = STATE_SPDY_READ_BODY; |
| 437 } else { |
| 438 DCHECK(!spdy_http_stream_.get()); |
| 439 next_state = STATE_READ_BODY; |
| 440 |
| 441 if (!connection_->is_initialized()) |
| 442 return 0; // |*connection_| has been reset. Treat like EOF. |
| 437 } | 443 } |
| 438 | 444 |
| 439 read_buf_ = buf; | 445 read_buf_ = buf; |
| 440 read_buf_len_ = buf_len; | 446 read_buf_len_ = buf_len; |
| 441 | 447 |
| 442 next_state_ = next_state; | 448 next_state_ = next_state; |
| 443 int rv = DoLoop(OK); | 449 int rv = DoLoop(OK); |
| 444 if (rv == ERR_IO_PENDING) | 450 if (rv == ERR_IO_PENDING) |
| 445 user_callback_ = callback; | 451 user_callback_ = callback; |
| 446 return rv; | 452 return rv; |
| 447 } | 453 } |
| 448 | 454 |
| 449 const HttpResponseInfo* HttpNetworkTransaction::GetResponseInfo() const { | 455 const HttpResponseInfo* HttpNetworkTransaction::GetResponseInfo() const { |
| 450 return ((headers_valid_ && response_.headers) || response_.ssl_info.cert || | 456 return ((headers_valid_ && response_.headers) || response_.ssl_info.cert || |
| 451 response_.cert_request_info) ? &response_ : NULL; | 457 response_.cert_request_info) ? &response_ : NULL; |
| 452 } | 458 } |
| 453 | 459 |
| 454 LoadState HttpNetworkTransaction::GetLoadState() const { | 460 LoadState HttpNetworkTransaction::GetLoadState() const { |
| 455 // TODO(wtc): Define a new LoadState value for the | 461 // TODO(wtc): Define a new LoadState value for the |
| 456 // STATE_INIT_CONNECTION_COMPLETE state, which delays the HTTP request. | 462 // STATE_INIT_CONNECTION_COMPLETE state, which delays the HTTP request. |
| 457 switch (next_state_) { | 463 switch (next_state_) { |
| 458 case STATE_RESOLVE_PROXY_COMPLETE: | 464 case STATE_RESOLVE_PROXY_COMPLETE: |
| 459 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 465 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
| 460 case STATE_INIT_CONNECTION_COMPLETE: | 466 case STATE_INIT_CONNECTION_COMPLETE: |
| 461 return connection_->GetLoadState(); | 467 return connection_->GetLoadState(); |
| 462 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE: | 468 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE: |
| 463 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE: | 469 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE: |
| 464 case STATE_SEND_REQUEST_COMPLETE: | 470 case STATE_SEND_REQUEST_COMPLETE: |
| 465 case STATE_INIT_STREAM_COMPLETE: | 471 case STATE_SPDY_GET_STREAM: |
| 472 case STATE_SPDY_SEND_REQUEST_COMPLETE: |
| 466 return LOAD_STATE_SENDING_REQUEST; | 473 return LOAD_STATE_SENDING_REQUEST; |
| 467 case STATE_READ_HEADERS_COMPLETE: | 474 case STATE_READ_HEADERS_COMPLETE: |
| 475 case STATE_SPDY_READ_HEADERS_COMPLETE: |
| 468 return LOAD_STATE_WAITING_FOR_RESPONSE; | 476 return LOAD_STATE_WAITING_FOR_RESPONSE; |
| 469 case STATE_READ_BODY_COMPLETE: | 477 case STATE_READ_BODY_COMPLETE: |
| 478 case STATE_SPDY_READ_BODY_COMPLETE: |
| 470 return LOAD_STATE_READING_RESPONSE; | 479 return LOAD_STATE_READING_RESPONSE; |
| 471 default: | 480 default: |
| 472 return LOAD_STATE_IDLE; | 481 return LOAD_STATE_IDLE; |
| 473 } | 482 } |
| 474 } | 483 } |
| 475 | 484 |
| 476 uint64 HttpNetworkTransaction::GetUploadProgress() const { | 485 uint64 HttpNetworkTransaction::GetUploadProgress() const { |
| 477 if (!stream_.get()) | 486 if (!http_stream_.get()) |
| 478 return 0; | 487 return 0; |
| 479 | 488 |
| 480 return stream_->GetUploadProgress(); | 489 return http_stream_->GetUploadProgress(); |
| 481 } | 490 } |
| 482 | 491 |
| 483 HttpNetworkTransaction::~HttpNetworkTransaction() { | 492 HttpNetworkTransaction::~HttpNetworkTransaction() { |
| 484 // If we still have an open socket, then make sure to disconnect it so it | 493 // If we still have an open socket, then make sure to disconnect it so it |
| 485 // won't call us back and we don't try to reuse it later on. However, | 494 // won't call us back and we don't try to reuse it later on. However, |
| 486 // don't close the socket if we should keep the connection alive. | 495 // don't close the socket if we should keep the connection alive. |
| 487 if (connection_.get() && connection_->is_initialized()) { | 496 if (connection_.get() && connection_->is_initialized()) { |
| 488 // The STATE_NONE check guarantees there are no pending socket IOs that | 497 // The STATE_NONE check guarantees there are no pending socket IOs that |
| 489 // could try to call this object back after it is deleted. | 498 // could try to call this object back after it is deleted. |
| 490 bool keep_alive = next_state_ == STATE_NONE && | 499 bool keep_alive = next_state_ == STATE_NONE && |
| 491 !using_spdy_ && | 500 http_stream_.get() && |
| 492 stream_.get() && | 501 http_stream_->IsResponseBodyComplete() && |
| 493 stream_->IsResponseBodyComplete() && | 502 http_stream_->CanFindEndOfResponse() && |
| 494 stream_->CanFindEndOfResponse() && | |
| 495 GetResponseHeaders()->IsKeepAlive(); | 503 GetResponseHeaders()->IsKeepAlive(); |
| 496 if (!keep_alive) | 504 if (!keep_alive) |
| 497 connection_->socket()->Disconnect(); | 505 connection_->socket()->Disconnect(); |
| 498 } | 506 } |
| 499 | 507 |
| 500 if (pac_request_) | 508 if (pac_request_) |
| 501 session_->proxy_service()->CancelPacRequest(pac_request_); | 509 session_->proxy_service()->CancelPacRequest(pac_request_); |
| 502 | 510 |
| 503 if (using_spdy_ && stream_.get()) | 511 if (spdy_http_stream_.get()) |
| 504 static_cast<SpdyHttpStream*>(stream_.get())->Cancel(); | 512 spdy_http_stream_->Cancel(); |
| 505 } | 513 } |
| 506 | 514 |
| 507 void HttpNetworkTransaction::DoCallback(int rv) { | 515 void HttpNetworkTransaction::DoCallback(int rv) { |
| 508 DCHECK(rv != ERR_IO_PENDING); | 516 DCHECK(rv != ERR_IO_PENDING); |
| 509 DCHECK(user_callback_); | 517 DCHECK(user_callback_); |
| 510 | 518 |
| 511 // Since Run may result in Read being called, clear user_callback_ up front. | 519 // Since Run may result in Read being called, clear user_callback_ up front. |
| 512 CompletionCallback* c = user_callback_; | 520 CompletionCallback* c = user_callback_; |
| 513 user_callback_ = NULL; | 521 user_callback_ = NULL; |
| 514 c->Run(rv); | 522 c->Run(rv); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 535 case STATE_RESOLVE_PROXY_COMPLETE: | 543 case STATE_RESOLVE_PROXY_COMPLETE: |
| 536 rv = DoResolveProxyComplete(rv); | 544 rv = DoResolveProxyComplete(rv); |
| 537 break; | 545 break; |
| 538 case STATE_INIT_CONNECTION: | 546 case STATE_INIT_CONNECTION: |
| 539 DCHECK_EQ(OK, rv); | 547 DCHECK_EQ(OK, rv); |
| 540 rv = DoInitConnection(); | 548 rv = DoInitConnection(); |
| 541 break; | 549 break; |
| 542 case STATE_INIT_CONNECTION_COMPLETE: | 550 case STATE_INIT_CONNECTION_COMPLETE: |
| 543 rv = DoInitConnectionComplete(rv); | 551 rv = DoInitConnectionComplete(rv); |
| 544 break; | 552 break; |
| 545 case STATE_INIT_STREAM: | |
| 546 DCHECK_EQ(OK, rv); | |
| 547 rv = DoInitStream(); | |
| 548 break; | |
| 549 case STATE_INIT_STREAM_COMPLETE: | |
| 550 rv = DoInitStreamComplete(rv); | |
| 551 break; | |
| 552 case STATE_RESTART_TUNNEL_AUTH: | 553 case STATE_RESTART_TUNNEL_AUTH: |
| 553 DCHECK_EQ(OK, rv); | 554 DCHECK_EQ(OK, rv); |
| 554 rv = DoRestartTunnelAuth(); | 555 rv = DoRestartTunnelAuth(); |
| 555 break; | 556 break; |
| 556 case STATE_RESTART_TUNNEL_AUTH_COMPLETE: | 557 case STATE_RESTART_TUNNEL_AUTH_COMPLETE: |
| 557 rv = DoRestartTunnelAuthComplete(rv); | 558 rv = DoRestartTunnelAuthComplete(rv); |
| 558 break; | 559 break; |
| 559 case STATE_GENERATE_PROXY_AUTH_TOKEN: | 560 case STATE_GENERATE_PROXY_AUTH_TOKEN: |
| 560 DCHECK_EQ(OK, rv); | 561 DCHECK_EQ(OK, rv); |
| 561 rv = DoGenerateProxyAuthToken(); | 562 rv = DoGenerateProxyAuthToken(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 DCHECK_EQ(OK, rv); | 602 DCHECK_EQ(OK, rv); |
| 602 net_log_.BeginEvent( | 603 net_log_.BeginEvent( |
| 603 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, NULL); | 604 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, NULL); |
| 604 rv = DoDrainBodyForAuthRestart(); | 605 rv = DoDrainBodyForAuthRestart(); |
| 605 break; | 606 break; |
| 606 case STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE: | 607 case STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE: |
| 607 rv = DoDrainBodyForAuthRestartComplete(rv); | 608 rv = DoDrainBodyForAuthRestartComplete(rv); |
| 608 net_log_.EndEvent( | 609 net_log_.EndEvent( |
| 609 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, NULL); | 610 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, NULL); |
| 610 break; | 611 break; |
| 612 case STATE_SPDY_GET_STREAM: |
| 613 DCHECK_EQ(OK, rv); |
| 614 rv = DoSpdyGetStream(); |
| 615 break; |
| 616 case STATE_SPDY_GET_STREAM_COMPLETE: |
| 617 rv = DoSpdyGetStreamComplete(rv); |
| 618 break; |
| 619 case STATE_SPDY_SEND_REQUEST: |
| 620 DCHECK_EQ(OK, rv); |
| 621 net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, NULL); |
| 622 rv = DoSpdySendRequest(); |
| 623 break; |
| 624 case STATE_SPDY_SEND_REQUEST_COMPLETE: |
| 625 rv = DoSpdySendRequestComplete(rv); |
| 626 net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, NULL); |
| 627 break; |
| 628 case STATE_SPDY_READ_HEADERS: |
| 629 DCHECK_EQ(OK, rv); |
| 630 net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, NULL); |
| 631 rv = DoSpdyReadHeaders(); |
| 632 break; |
| 633 case STATE_SPDY_READ_HEADERS_COMPLETE: |
| 634 rv = DoSpdyReadHeadersComplete(rv); |
| 635 net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, NULL); |
| 636 break; |
| 637 case STATE_SPDY_READ_BODY: |
| 638 DCHECK_EQ(OK, rv); |
| 639 net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, NULL); |
| 640 rv = DoSpdyReadBody(); |
| 641 break; |
| 642 case STATE_SPDY_READ_BODY_COMPLETE: |
| 643 rv = DoSpdyReadBodyComplete(rv); |
| 644 net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, NULL); |
| 645 break; |
| 611 default: | 646 default: |
| 612 NOTREACHED() << "bad state"; | 647 NOTREACHED() << "bad state"; |
| 613 rv = ERR_FAILED; | 648 rv = ERR_FAILED; |
| 614 break; | 649 break; |
| 615 } | 650 } |
| 616 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 651 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 617 | 652 |
| 618 return rv; | 653 return rv; |
| 619 } | 654 } |
| 620 | 655 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 want_spdy_over_npn; | 741 want_spdy_over_npn; |
| 707 using_spdy_ = false; | 742 using_spdy_ = false; |
| 708 response_.was_fetched_via_proxy = !proxy_info_.is_direct(); | 743 response_.was_fetched_via_proxy = !proxy_info_.is_direct(); |
| 709 | 744 |
| 710 // Check first if we have a spdy session for this group. If so, then go | 745 // Check first if we have a spdy session for this group. If so, then go |
| 711 // straight to using that. | 746 // straight to using that. |
| 712 HostPortProxyPair pair(endpoint_, proxy_info_.ToPacString()); | 747 HostPortProxyPair pair(endpoint_, proxy_info_.ToPacString()); |
| 713 if (session_->spdy_session_pool()->HasSession(pair)) { | 748 if (session_->spdy_session_pool()->HasSession(pair)) { |
| 714 using_spdy_ = true; | 749 using_spdy_ = true; |
| 715 reused_socket_ = true; | 750 reused_socket_ = true; |
| 716 next_state_ = STATE_INIT_STREAM; | 751 next_state_ = STATE_SPDY_GET_STREAM; |
| 717 spdy_session_ = | |
| 718 session_->spdy_session_pool()->Get(pair, session_, net_log_); | |
| 719 return OK; | 752 return OK; |
| 720 } | 753 } |
| 721 | 754 |
| 722 // Build the string used to uniquely identify connections of this type. | 755 // Build the string used to uniquely identify connections of this type. |
| 723 // Determine the host and port to connect to. | 756 // Determine the host and port to connect to. |
| 724 std::string connection_group = endpoint_.ToString(); | 757 std::string connection_group = endpoint_.ToString(); |
| 725 DCHECK(!connection_group.empty()); | 758 DCHECK(!connection_group.empty()); |
| 726 | 759 |
| 727 if (using_ssl_) | 760 if (using_ssl_) |
| 728 connection_group = StringPrintf("ssl/%s", connection_group.c_str()); | 761 connection_group = StringPrintf("ssl/%s", connection_group.c_str()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 if (!reused_socket_) { | 949 if (!reused_socket_) { |
| 917 if (using_spdy_) | 950 if (using_spdy_) |
| 918 UpdateConnectionTypeHistograms(CONNECTION_SPDY); | 951 UpdateConnectionTypeHistograms(CONNECTION_SPDY); |
| 919 else | 952 else |
| 920 UpdateConnectionTypeHistograms(CONNECTION_HTTP); | 953 UpdateConnectionTypeHistograms(CONNECTION_HTTP); |
| 921 } | 954 } |
| 922 | 955 |
| 923 if (!using_ssl_) { | 956 if (!using_ssl_) { |
| 924 DCHECK_EQ(OK, result); | 957 DCHECK_EQ(OK, result); |
| 925 if (using_spdy_) | 958 if (using_spdy_) |
| 926 next_state_ = STATE_INIT_STREAM; | 959 next_state_ = STATE_SPDY_GET_STREAM; |
| 927 else | 960 else |
| 928 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; | 961 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; |
| 929 return result; | 962 return result; |
| 930 } | 963 } |
| 931 } | 964 } |
| 932 | 965 |
| 933 // Handle SSL errors below. | 966 // Handle SSL errors below. |
| 934 DCHECK(using_ssl_); | 967 DCHECK(using_ssl_); |
| 935 DCHECK(ssl_started); | 968 DCHECK(ssl_started); |
| 936 if (IsCertificateError(result)) { | 969 if (IsCertificateError(result)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 953 response_.cert_request_info = | 986 response_.cert_request_info = |
| 954 connection_->ssl_error_response_info().cert_request_info; | 987 connection_->ssl_error_response_info().cert_request_info; |
| 955 return HandleCertificateRequest(result); | 988 return HandleCertificateRequest(result); |
| 956 } | 989 } |
| 957 if (result < 0) | 990 if (result < 0) |
| 958 return HandleSSLHandshakeError(result); | 991 return HandleSSLHandshakeError(result); |
| 959 | 992 |
| 960 if (using_spdy_) { | 993 if (using_spdy_) { |
| 961 UpdateConnectionTypeHistograms(CONNECTION_SPDY); | 994 UpdateConnectionTypeHistograms(CONNECTION_SPDY); |
| 962 // TODO(cbentzel): Add auth support to spdy. See http://crbug.com/46620 | 995 // TODO(cbentzel): Add auth support to spdy. See http://crbug.com/46620 |
| 963 next_state_ = STATE_INIT_STREAM; | 996 next_state_ = STATE_SPDY_GET_STREAM; |
| 964 } else { | 997 } else { |
| 965 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; | 998 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; |
| 966 } | 999 } |
| 967 return OK; | 1000 return OK; |
| 968 } | 1001 } |
| 969 | 1002 |
| 970 int HttpNetworkTransaction::DoInitStream() { | |
| 971 next_state_ = STATE_INIT_STREAM_COMPLETE; | |
| 972 | |
| 973 if (!using_spdy_) { | |
| 974 stream_.reset(new HttpBasicStream(connection_.get())); | |
| 975 return stream_->InitializeStream(request_, net_log_, &io_callback_); | |
| 976 } | |
| 977 | |
| 978 CHECK(!stream_.get()); | |
| 979 | |
| 980 const scoped_refptr<SpdySessionPool> spdy_pool = | |
| 981 session_->spdy_session_pool(); | |
| 982 | |
| 983 HostPortProxyPair pair(endpoint_, proxy_info_.ToPacString()); | |
| 984 if (!spdy_session_.get()) { | |
| 985 // SPDY can be negotiated using the TLS next protocol negotiation (NPN) | |
| 986 // extension, or just directly using SSL. Either way, |connection_| must | |
| 987 // contain an SSLClientSocket. | |
| 988 CHECK(connection_->socket()); | |
| 989 int error = spdy_pool->GetSpdySessionFromSocket( | |
| 990 pair, session_, connection_.release(), net_log_, | |
| 991 spdy_certificate_error_, &spdy_session_, using_ssl_); | |
| 992 if (error != OK) | |
| 993 return error; | |
| 994 } | |
| 995 CHECK(spdy_session_.get()); | |
| 996 if (spdy_session_->IsClosed()) | |
| 997 return ERR_CONNECTION_CLOSED; | |
| 998 | |
| 999 headers_valid_ = false; | |
| 1000 | |
| 1001 stream_.reset(new SpdyHttpStream(spdy_session_.release())); | |
| 1002 return stream_->InitializeStream(request_, net_log_, &io_callback_); | |
| 1003 } | |
| 1004 | |
| 1005 int HttpNetworkTransaction::DoInitStreamComplete(int result) { | |
| 1006 if (result < 0) | |
| 1007 return result; | |
| 1008 | |
| 1009 next_state_ = STATE_SEND_REQUEST; | |
| 1010 return OK; | |
| 1011 } | |
| 1012 | |
| 1013 int HttpNetworkTransaction::DoRestartTunnelAuth() { | 1003 int HttpNetworkTransaction::DoRestartTunnelAuth() { |
| 1014 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; | 1004 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; |
| 1015 HttpProxyClientSocket* http_proxy_socket = | 1005 HttpProxyClientSocket* http_proxy_socket = |
| 1016 static_cast<HttpProxyClientSocket*>(connection_->socket()); | 1006 static_cast<HttpProxyClientSocket*>(connection_->socket()); |
| 1017 return http_proxy_socket->RestartWithAuth(&io_callback_); | 1007 return http_proxy_socket->RestartWithAuth(&io_callback_); |
| 1018 } | 1008 } |
| 1019 | 1009 |
| 1020 int HttpNetworkTransaction::DoRestartTunnelAuthComplete(int result) { | 1010 int HttpNetworkTransaction::DoRestartTunnelAuthComplete(int result) { |
| 1021 if (result == ERR_PROXY_AUTH_REQUESTED) | 1011 if (result == ERR_PROXY_AUTH_REQUESTED) |
| 1022 return HandleTunnelAuthFailure(result); | 1012 return HandleTunnelAuthFailure(result); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 if (!ShouldApplyServerAuth()) | 1056 if (!ShouldApplyServerAuth()) |
| 1067 return OK; | 1057 return OK; |
| 1068 return auth_controllers_[target]->MaybeGenerateAuthToken(request_, | 1058 return auth_controllers_[target]->MaybeGenerateAuthToken(request_, |
| 1069 &io_callback_, | 1059 &io_callback_, |
| 1070 net_log_); | 1060 net_log_); |
| 1071 } | 1061 } |
| 1072 | 1062 |
| 1073 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { | 1063 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { |
| 1074 DCHECK_NE(ERR_IO_PENDING, rv); | 1064 DCHECK_NE(ERR_IO_PENDING, rv); |
| 1075 if (rv == OK) | 1065 if (rv == OK) |
| 1076 next_state_ = STATE_INIT_STREAM; | 1066 next_state_ = STATE_SEND_REQUEST; |
| 1077 return rv; | 1067 return rv; |
| 1078 } | 1068 } |
| 1079 | 1069 |
| 1080 int HttpNetworkTransaction::DoSendRequest() { | 1070 int HttpNetworkTransaction::DoSendRequest() { |
| 1081 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1071 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 1082 | 1072 |
| 1083 UploadDataStream* request_body = NULL; | 1073 UploadDataStream* request_body = NULL; |
| 1084 if (request_->upload_data) { | 1074 if (request_->upload_data) { |
| 1085 int error_code; | 1075 int error_code; |
| 1086 request_body = UploadDataStream::Create(request_->upload_data, &error_code); | 1076 request_body = UploadDataStream::Create(request_->upload_data, &error_code); |
| 1087 if (!request_body) | 1077 if (!request_body) |
| 1088 return error_code; | 1078 return error_code; |
| 1089 } | 1079 } |
| 1090 | 1080 |
| 1091 // This is constructed lazily (instead of within our Start method), so that | 1081 // This is constructed lazily (instead of within our Start method), so that |
| 1092 // we have proxy info available. | 1082 // we have proxy info available. |
| 1093 if (request_headers_.empty() && !using_spdy_) { | 1083 if (request_headers_.empty()) { |
| 1094 // Figure out if we can/should add Proxy-Authentication & Authentication | 1084 // Figure out if we can/should add Proxy-Authentication & Authentication |
| 1095 // headers. | 1085 // headers. |
| 1096 HttpRequestHeaders authorization_headers; | 1086 HttpRequestHeaders authorization_headers; |
| 1097 bool have_proxy_auth = (ShouldApplyProxyAuth() && | 1087 bool have_proxy_auth = (ShouldApplyProxyAuth() && |
| 1098 HaveAuth(HttpAuth::AUTH_PROXY)); | 1088 HaveAuth(HttpAuth::AUTH_PROXY)); |
| 1099 bool have_server_auth = (ShouldApplyServerAuth() && | 1089 bool have_server_auth = (ShouldApplyServerAuth() && |
| 1100 HaveAuth(HttpAuth::AUTH_SERVER)); | 1090 HaveAuth(HttpAuth::AUTH_SERVER)); |
| 1101 if (have_proxy_auth) | 1091 if (have_proxy_auth) |
| 1102 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( | 1092 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( |
| 1103 &authorization_headers); | 1093 &authorization_headers); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1116 if (net_log_.HasListener()) { | 1106 if (net_log_.HasListener()) { |
| 1117 net_log_.AddEvent( | 1107 net_log_.AddEvent( |
| 1118 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | 1108 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 1119 new NetLogHttpRequestParameter(request_line, request_headers)); | 1109 new NetLogHttpRequestParameter(request_line, request_headers)); |
| 1120 } | 1110 } |
| 1121 | 1111 |
| 1122 request_headers_ = request_line + request_headers.ToString(); | 1112 request_headers_ = request_line + request_headers.ToString(); |
| 1123 } | 1113 } |
| 1124 | 1114 |
| 1125 headers_valid_ = false; | 1115 headers_valid_ = false; |
| 1126 return stream_->SendRequest(request_headers_, request_body, &response_, | 1116 http_stream_.reset(new HttpBasicStream(connection_.get())); |
| 1127 &io_callback_); | 1117 http_stream_->InitializeStream(request_, net_log_, NULL); |
| 1118 return http_stream_->SendRequest(request_headers_, request_body, &response_, |
| 1119 &io_callback_); |
| 1128 } | 1120 } |
| 1129 | 1121 |
| 1130 int HttpNetworkTransaction::DoSendRequestComplete(int result) { | 1122 int HttpNetworkTransaction::DoSendRequestComplete(int result) { |
| 1131 if (result < 0) | 1123 if (result < 0) |
| 1132 return HandleIOError(result); | 1124 return HandleIOError(result); |
| 1133 next_state_ = STATE_READ_HEADERS; | 1125 next_state_ = STATE_READ_HEADERS; |
| 1134 return OK; | 1126 return OK; |
| 1135 } | 1127 } |
| 1136 | 1128 |
| 1137 int HttpNetworkTransaction::DoReadHeaders() { | 1129 int HttpNetworkTransaction::DoReadHeaders() { |
| 1138 next_state_ = STATE_READ_HEADERS_COMPLETE; | 1130 next_state_ = STATE_READ_HEADERS_COMPLETE; |
| 1139 return stream_->ReadResponseHeaders(&io_callback_); | 1131 return http_stream_->ReadResponseHeaders(&io_callback_); |
| 1140 } | 1132 } |
| 1141 | 1133 |
| 1142 int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() { | 1134 int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() { |
| 1143 if (!response_.headers) { | 1135 if (!response_.headers) { |
| 1144 // The connection was closed before any data was sent. Likely an error | 1136 // The connection was closed before any data was sent. Likely an error |
| 1145 // rather than empty HTTP/0.9 response. | 1137 // rather than empty HTTP/0.9 response. |
| 1146 return ERR_EMPTY_RESPONSE; | 1138 return ERR_EMPTY_RESPONSE; |
| 1147 } | 1139 } |
| 1148 | 1140 |
| 1149 return OK; | 1141 return OK; |
| 1150 } | 1142 } |
| 1151 | 1143 |
| 1152 int HttpNetworkTransaction::DoReadHeadersComplete(int result) { | 1144 int HttpNetworkTransaction::DoReadHeadersComplete(int result) { |
| 1153 if (using_spdy_) { | |
| 1154 // TODO(willchan): Flesh out the support for HTTP authentication here. | |
| 1155 if (result < 0) | |
| 1156 return HandleIOError(result); | |
| 1157 | |
| 1158 if (result == OK) | |
| 1159 headers_valid_ = true; | |
| 1160 | |
| 1161 LogTransactionConnectedMetrics(); | |
| 1162 return result; | |
| 1163 } | |
| 1164 | |
| 1165 // We can get a certificate error or ERR_SSL_CLIENT_AUTH_CERT_NEEDED here | 1145 // We can get a certificate error or ERR_SSL_CLIENT_AUTH_CERT_NEEDED here |
| 1166 // due to SSL renegotiation. | 1146 // due to SSL renegotiation. |
| 1167 if (using_ssl_) { | 1147 if (using_ssl_) { |
| 1168 if (IsCertificateError(result)) { | 1148 if (IsCertificateError(result)) { |
| 1169 // We don't handle a certificate error during SSL renegotiation, so we | 1149 // We don't handle a certificate error during SSL renegotiation, so we |
| 1170 // have to return an error that's not in the certificate error range | 1150 // have to return an error that's not in the certificate error range |
| 1171 // (-2xx). | 1151 // (-2xx). |
| 1172 LOG(ERROR) << "Got a server certificate with error " << result | 1152 LOG(ERROR) << "Got a server certificate with error " << result |
| 1173 << " during SSL renegotiation"; | 1153 << " during SSL renegotiation"; |
| 1174 result = ERR_CERT_ERROR_IN_SSL_RENEGOTIATION; | 1154 result = ERR_CERT_ERROR_IN_SSL_RENEGOTIATION; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 ssl_socket->GetSSLInfo(&response_.ssl_info); | 1240 ssl_socket->GetSSLInfo(&response_.ssl_info); |
| 1261 } | 1241 } |
| 1262 | 1242 |
| 1263 headers_valid_ = true; | 1243 headers_valid_ = true; |
| 1264 return OK; | 1244 return OK; |
| 1265 } | 1245 } |
| 1266 | 1246 |
| 1267 int HttpNetworkTransaction::DoReadBody() { | 1247 int HttpNetworkTransaction::DoReadBody() { |
| 1268 DCHECK(read_buf_); | 1248 DCHECK(read_buf_); |
| 1269 DCHECK_GT(read_buf_len_, 0); | 1249 DCHECK_GT(read_buf_len_, 0); |
| 1270 if (!using_spdy_) | 1250 DCHECK(connection_->is_initialized()); |
| 1271 DCHECK(connection_->is_initialized()); | |
| 1272 | 1251 |
| 1273 next_state_ = STATE_READ_BODY_COMPLETE; | 1252 next_state_ = STATE_READ_BODY_COMPLETE; |
| 1274 return stream_->ReadResponseBody(read_buf_, read_buf_len_, &io_callback_); | 1253 return http_stream_->ReadResponseBody(read_buf_, read_buf_len_, |
| 1254 &io_callback_); |
| 1275 } | 1255 } |
| 1276 | 1256 |
| 1277 int HttpNetworkTransaction::DoReadBodyComplete(int result) { | 1257 int HttpNetworkTransaction::DoReadBodyComplete(int result) { |
| 1278 // We are done with the Read call. | 1258 // We are done with the Read call. |
| 1279 bool done = false, keep_alive = false; | 1259 bool done = false, keep_alive = false; |
| 1280 if (result <= 0) | 1260 if (result <= 0) |
| 1281 done = true; | 1261 done = true; |
| 1282 | 1262 |
| 1283 if (stream_->IsResponseBodyComplete()) { | 1263 if (http_stream_->IsResponseBodyComplete()) { |
| 1284 done = true; | 1264 done = true; |
| 1285 if (stream_->CanFindEndOfResponse()) | 1265 if (http_stream_->CanFindEndOfResponse()) |
| 1286 keep_alive = GetResponseHeaders()->IsKeepAlive(); | 1266 keep_alive = GetResponseHeaders()->IsKeepAlive(); |
| 1287 } | 1267 } |
| 1288 | 1268 |
| 1289 // Clean up connection_->if we are done. | 1269 // Clean up connection_->if we are done. |
| 1290 if (done) { | 1270 if (done) { |
| 1291 LogTransactionMetrics(); | 1271 LogTransactionMetrics(); |
| 1292 if (!using_spdy_) { | 1272 if (!keep_alive) |
| 1293 if (!keep_alive) | 1273 connection_->socket()->Disconnect(); |
| 1294 connection_->socket()->Disconnect(); | 1274 connection_->Reset(); |
| 1295 connection_->Reset(); | 1275 // The next Read call will return 0 (EOF). |
| 1296 // The next Read call will return 0 (EOF). | |
| 1297 } | |
| 1298 } | 1276 } |
| 1299 | 1277 |
| 1300 // Clear these to avoid leaving around old state. | 1278 // Clear these to avoid leaving around old state. |
| 1301 read_buf_ = NULL; | 1279 read_buf_ = NULL; |
| 1302 read_buf_len_ = 0; | 1280 read_buf_len_ = 0; |
| 1303 | 1281 |
| 1304 return result; | 1282 return result; |
| 1305 } | 1283 } |
| 1306 | 1284 |
| 1307 int HttpNetworkTransaction::DoDrainBodyForAuthRestart() { | 1285 int HttpNetworkTransaction::DoDrainBodyForAuthRestart() { |
| 1308 // This method differs from DoReadBody only in the next_state_. So we just | 1286 // This method differs from DoReadBody only in the next_state_. So we just |
| 1309 // call DoReadBody and override the next_state_. Perhaps there is a more | 1287 // call DoReadBody and override the next_state_. Perhaps there is a more |
| 1310 // elegant way for these two methods to share code. | 1288 // elegant way for these two methods to share code. |
| 1311 int rv = DoReadBody(); | 1289 int rv = DoReadBody(); |
| 1312 DCHECK(next_state_ == STATE_READ_BODY_COMPLETE); | 1290 DCHECK(next_state_ == STATE_READ_BODY_COMPLETE); |
| 1313 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE; | 1291 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE; |
| 1314 return rv; | 1292 return rv; |
| 1315 } | 1293 } |
| 1316 | 1294 |
| 1317 // TODO(wtc): This method and the DoReadBodyComplete method are almost | 1295 // TODO(wtc): This method and the DoReadBodyComplete method are almost |
| 1318 // the same. Figure out a good way for these two methods to share code. | 1296 // the same. Figure out a good way for these two methods to share code. |
| 1319 int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { | 1297 int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { |
| 1320 // keep_alive defaults to true because the very reason we're draining the | 1298 // keep_alive defaults to true because the very reason we're draining the |
| 1321 // response body is to reuse the connection for auth restart. | 1299 // response body is to reuse the connection for auth restart. |
| 1322 bool done = false, keep_alive = true; | 1300 bool done = false, keep_alive = true; |
| 1323 if (result < 0) { | 1301 if (result < 0) { |
| 1324 // Error or closed connection while reading the socket. | 1302 // Error or closed connection while reading the socket. |
| 1325 done = true; | 1303 done = true; |
| 1326 keep_alive = false; | 1304 keep_alive = false; |
| 1327 } else if (stream_->IsResponseBodyComplete()) { | 1305 } else if (http_stream_->IsResponseBodyComplete()) { |
| 1328 done = true; | 1306 done = true; |
| 1329 } | 1307 } |
| 1330 | 1308 |
| 1331 if (done) { | 1309 if (done) { |
| 1332 DidDrainBodyForAuthRestart(keep_alive); | 1310 DidDrainBodyForAuthRestart(keep_alive); |
| 1333 } else { | 1311 } else { |
| 1334 // Keep draining. | 1312 // Keep draining. |
| 1335 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; | 1313 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; |
| 1336 } | 1314 } |
| 1337 | 1315 |
| 1338 return OK; | 1316 return OK; |
| 1339 } | 1317 } |
| 1340 | 1318 |
| 1319 int HttpNetworkTransaction::DoSpdyGetStream() { |
| 1320 next_state_ = STATE_SPDY_GET_STREAM_COMPLETE; |
| 1321 CHECK(!spdy_http_stream_.get()); |
| 1322 |
| 1323 // First we get a SPDY session. Theoretically, we've just negotiated one, but |
| 1324 // if one already exists, then screw it, use the existing one! Otherwise, |
| 1325 // use the existing TCP socket. |
| 1326 |
| 1327 const scoped_refptr<SpdySessionPool> spdy_pool = |
| 1328 session_->spdy_session_pool(); |
| 1329 scoped_refptr<SpdySession> spdy_session; |
| 1330 |
| 1331 HostPortProxyPair pair(endpoint_, proxy_info_.ToPacString()); |
| 1332 if (spdy_pool->HasSession(pair)) { |
| 1333 spdy_session = spdy_pool->Get(pair, session_, net_log_); |
| 1334 } else { |
| 1335 if(using_ssl_) { |
| 1336 // SPDY can be negotiated using the TLS next protocol negotiation (NPN) |
| 1337 // extension, or just directly using SSL. Either way, |connection_| must |
| 1338 // contain an SSLClientSocket. |
| 1339 CHECK(connection_->socket()); |
| 1340 int error = spdy_pool->GetSpdySessionFromSocket( |
| 1341 pair, session_, connection_.release(), net_log_, |
| 1342 spdy_certificate_error_, &spdy_session, true); |
| 1343 if (error != OK) |
| 1344 return error; |
| 1345 } |
| 1346 else { |
| 1347 // We may want SPDY without SSL |
| 1348 int error = spdy_pool->GetSpdySessionFromSocket( |
| 1349 pair, session_, connection_.release(), net_log_, |
| 1350 spdy_certificate_error_, &spdy_session, false); |
| 1351 if (error != OK) |
| 1352 return error; |
| 1353 } |
| 1354 } |
| 1355 |
| 1356 CHECK(spdy_session.get()); |
| 1357 if (spdy_session->IsClosed()) |
| 1358 return ERR_CONNECTION_CLOSED; |
| 1359 |
| 1360 headers_valid_ = false; |
| 1361 |
| 1362 spdy_http_stream_.reset(new SpdyHttpStream(spdy_session)); |
| 1363 return spdy_http_stream_->InitializeStream(request_, net_log_, &io_callback_); |
| 1364 } |
| 1365 |
| 1366 int HttpNetworkTransaction::DoSpdyGetStreamComplete(int result) { |
| 1367 if (result < 0) |
| 1368 return result; |
| 1369 |
| 1370 next_state_ = STATE_SPDY_SEND_REQUEST; |
| 1371 return OK; |
| 1372 } |
| 1373 |
| 1374 int HttpNetworkTransaction::DoSpdySendRequest() { |
| 1375 next_state_ = STATE_SPDY_SEND_REQUEST_COMPLETE; |
| 1376 |
| 1377 UploadDataStream* upload_data_stream = NULL; |
| 1378 if (request_->upload_data) { |
| 1379 int error_code = OK; |
| 1380 upload_data_stream = UploadDataStream::Create(request_->upload_data, |
| 1381 &error_code); |
| 1382 if (!upload_data_stream) |
| 1383 return error_code; |
| 1384 } |
| 1385 return spdy_http_stream_->SendRequest(request_headers_, upload_data_stream, |
| 1386 &response_, &io_callback_); |
| 1387 } |
| 1388 |
| 1389 int HttpNetworkTransaction::DoSpdySendRequestComplete(int result) { |
| 1390 if (result < 0) |
| 1391 return HandleIOError(result); |
| 1392 |
| 1393 next_state_ = STATE_SPDY_READ_HEADERS; |
| 1394 return OK; |
| 1395 } |
| 1396 |
| 1397 int HttpNetworkTransaction::DoSpdyReadHeaders() { |
| 1398 next_state_ = STATE_SPDY_READ_HEADERS_COMPLETE; |
| 1399 return spdy_http_stream_->ReadResponseHeaders(&io_callback_); |
| 1400 } |
| 1401 |
| 1402 int HttpNetworkTransaction::DoSpdyReadHeadersComplete(int result) { |
| 1403 // TODO(willchan): Flesh out the support for HTTP authentication here. |
| 1404 if (result < 0) |
| 1405 return HandleIOError(result); |
| 1406 |
| 1407 if (result == OK) |
| 1408 headers_valid_ = true; |
| 1409 |
| 1410 LogTransactionConnectedMetrics(); |
| 1411 return result; |
| 1412 } |
| 1413 |
| 1414 int HttpNetworkTransaction::DoSpdyReadBody() { |
| 1415 next_state_ = STATE_SPDY_READ_BODY_COMPLETE; |
| 1416 |
| 1417 return spdy_http_stream_->ReadResponseBody( |
| 1418 read_buf_, read_buf_len_, &io_callback_); |
| 1419 } |
| 1420 |
| 1421 int HttpNetworkTransaction::DoSpdyReadBodyComplete(int result) { |
| 1422 read_buf_ = NULL; |
| 1423 read_buf_len_ = 0; |
| 1424 |
| 1425 if (result <= 0) |
| 1426 spdy_http_stream_.reset(); |
| 1427 |
| 1428 return result; |
| 1429 } |
| 1430 |
| 1341 void HttpNetworkTransaction::LogHttpConnectedMetrics( | 1431 void HttpNetworkTransaction::LogHttpConnectedMetrics( |
| 1342 const ClientSocketHandle& handle) { | 1432 const ClientSocketHandle& handle) { |
| 1343 UMA_HISTOGRAM_ENUMERATION("Net.HttpSocketType", handle.reuse_type(), | 1433 UMA_HISTOGRAM_ENUMERATION("Net.HttpSocketType", handle.reuse_type(), |
| 1344 ClientSocketHandle::NUM_TYPES); | 1434 ClientSocketHandle::NUM_TYPES); |
| 1345 | 1435 |
| 1346 switch (handle.reuse_type()) { | 1436 switch (handle.reuse_type()) { |
| 1347 case ClientSocketHandle::UNUSED: | 1437 case ClientSocketHandle::UNUSED: |
| 1348 UMA_HISTOGRAM_CUSTOM_TIMES("Net.HttpConnectionLatency", | 1438 UMA_HISTOGRAM_CUSTOM_TIMES("Net.HttpConnectionLatency", |
| 1349 handle.setup_time(), | 1439 handle.setup_time(), |
| 1350 base::TimeDelta::FromMilliseconds(1), | 1440 base::TimeDelta::FromMilliseconds(1), |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 } | 1699 } |
| 1610 break; | 1700 break; |
| 1611 } | 1701 } |
| 1612 return error; | 1702 return error; |
| 1613 } | 1703 } |
| 1614 | 1704 |
| 1615 void HttpNetworkTransaction::ResetStateForRestart() { | 1705 void HttpNetworkTransaction::ResetStateForRestart() { |
| 1616 pending_auth_target_ = HttpAuth::AUTH_NONE; | 1706 pending_auth_target_ = HttpAuth::AUTH_NONE; |
| 1617 read_buf_ = NULL; | 1707 read_buf_ = NULL; |
| 1618 read_buf_len_ = 0; | 1708 read_buf_len_ = 0; |
| 1619 stream_.reset(); | 1709 http_stream_.reset(); |
| 1620 headers_valid_ = false; | 1710 headers_valid_ = false; |
| 1621 request_headers_.clear(); | 1711 request_headers_.clear(); |
| 1622 response_ = HttpResponseInfo(); | 1712 response_ = HttpResponseInfo(); |
| 1623 } | 1713 } |
| 1624 | 1714 |
| 1625 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { | 1715 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { |
| 1626 return response_.headers; | 1716 return response_.headers; |
| 1627 } | 1717 } |
| 1628 | 1718 |
| 1629 bool HttpNetworkTransaction::ShouldResendRequest(int error) const { | 1719 bool HttpNetworkTransaction::ShouldResendRequest(int error) const { |
| 1630 if (using_spdy_ && stream_ != NULL) | 1720 if (using_spdy_ && spdy_http_stream_ != NULL) |
| 1631 return static_cast<SpdyHttpStream *>(stream_.get())-> | 1721 return spdy_http_stream_->ShouldResendFailedRequest(error); |
| 1632 ShouldResendFailedRequest(error); | |
| 1633 | 1722 |
| 1634 // NOTE: we resend a request only if we reused a keep-alive connection. | 1723 // NOTE: we resend a request only if we reused a keep-alive connection. |
| 1635 // This automatically prevents an infinite resend loop because we'll run | 1724 // This automatically prevents an infinite resend loop because we'll run |
| 1636 // out of the cached keep-alive connections eventually. | 1725 // out of the cached keep-alive connections eventually. |
| 1637 if (!connection_->ShouldResendFailedRequest(error) || | 1726 if (!connection_->ShouldResendFailedRequest(error) || |
| 1638 GetResponseHeaders()) { // We have received some response headers. | 1727 GetResponseHeaders()) { // We have received some response headers. |
| 1639 return false; | 1728 return false; |
| 1640 } | 1729 } |
| 1641 return true; | 1730 return true; |
| 1642 } | 1731 } |
| 1643 | 1732 |
| 1644 void HttpNetworkTransaction::ResetConnectionAndRequestForResend() { | 1733 void HttpNetworkTransaction::ResetConnectionAndRequestForResend() { |
| 1645 // Note: When using SPDY we may not own a connection. | 1734 // Note: When using SPDY we may not own a connection. |
| 1646 if (connection_.get()) { | 1735 if (connection_.get()) { |
| 1647 if (connection_->socket()) | 1736 if (connection_->socket()) |
| 1648 connection_->socket()->Disconnect(); | 1737 connection_->socket()->Disconnect(); |
| 1649 connection_->Reset(); | 1738 connection_->Reset(); |
| 1650 } else { | 1739 } else { |
| 1651 DCHECK(using_spdy_); | 1740 DCHECK(using_spdy_); |
| 1652 connection_.reset(new ClientSocketHandle); | 1741 connection_.reset(new ClientSocketHandle); |
| 1653 } | 1742 } |
| 1654 | 1743 |
| 1655 // We need to clear request_headers_ because it contains the real request | 1744 // We need to clear request_headers_ because it contains the real request |
| 1656 // headers, but we may need to resend the CONNECT request first to recreate | 1745 // headers, but we may need to resend the CONNECT request first to recreate |
| 1657 // the SSL tunnel. | 1746 // the SSL tunnel. |
| 1658 | 1747 |
| 1659 stream_.reset(NULL); | 1748 spdy_http_stream_.reset(NULL); |
| 1660 | 1749 |
| 1661 request_headers_.clear(); | 1750 request_headers_.clear(); |
| 1662 next_state_ = STATE_INIT_CONNECTION; // Resend the request. | 1751 next_state_ = STATE_INIT_CONNECTION; // Resend the request. |
| 1663 } | 1752 } |
| 1664 | 1753 |
| 1665 int HttpNetworkTransaction::ReconsiderProxyAfterError(int error) { | 1754 int HttpNetworkTransaction::ReconsiderProxyAfterError(int error) { |
| 1666 DCHECK(!pac_request_); | 1755 DCHECK(!pac_request_); |
| 1667 | 1756 |
| 1668 // A failure to resolve the hostname or any error related to establishing a | 1757 // A failure to resolve the hostname or any error related to establishing a |
| 1669 // TCP connection could be grounds for trying a new proxy configuration. | 1758 // TCP connection could be grounds for trying a new proxy configuration. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 description = StringPrintf("%s (0x%08X)", #s, s); \ | 1887 description = StringPrintf("%s (0x%08X)", #s, s); \ |
| 1799 break | 1888 break |
| 1800 | 1889 |
| 1801 std::string HttpNetworkTransaction::DescribeState(State state) { | 1890 std::string HttpNetworkTransaction::DescribeState(State state) { |
| 1802 std::string description; | 1891 std::string description; |
| 1803 switch (state) { | 1892 switch (state) { |
| 1804 STATE_CASE(STATE_RESOLVE_PROXY); | 1893 STATE_CASE(STATE_RESOLVE_PROXY); |
| 1805 STATE_CASE(STATE_RESOLVE_PROXY_COMPLETE); | 1894 STATE_CASE(STATE_RESOLVE_PROXY_COMPLETE); |
| 1806 STATE_CASE(STATE_INIT_CONNECTION); | 1895 STATE_CASE(STATE_INIT_CONNECTION); |
| 1807 STATE_CASE(STATE_INIT_CONNECTION_COMPLETE); | 1896 STATE_CASE(STATE_INIT_CONNECTION_COMPLETE); |
| 1808 STATE_CASE(STATE_INIT_STREAM); | |
| 1809 STATE_CASE(STATE_INIT_STREAM_COMPLETE); | |
| 1810 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN); | 1897 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN); |
| 1811 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE); | 1898 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE); |
| 1812 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN); | 1899 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN); |
| 1813 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE); | 1900 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE); |
| 1814 STATE_CASE(STATE_SEND_REQUEST); | 1901 STATE_CASE(STATE_SEND_REQUEST); |
| 1815 STATE_CASE(STATE_SEND_REQUEST_COMPLETE); | 1902 STATE_CASE(STATE_SEND_REQUEST_COMPLETE); |
| 1816 STATE_CASE(STATE_READ_HEADERS); | 1903 STATE_CASE(STATE_READ_HEADERS); |
| 1817 STATE_CASE(STATE_READ_HEADERS_COMPLETE); | 1904 STATE_CASE(STATE_READ_HEADERS_COMPLETE); |
| 1818 STATE_CASE(STATE_READ_BODY); | 1905 STATE_CASE(STATE_READ_BODY); |
| 1819 STATE_CASE(STATE_READ_BODY_COMPLETE); | 1906 STATE_CASE(STATE_READ_BODY_COMPLETE); |
| 1820 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); | 1907 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); |
| 1821 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); | 1908 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); |
| 1909 STATE_CASE(STATE_SPDY_GET_STREAM); |
| 1910 STATE_CASE(STATE_SPDY_GET_STREAM_COMPLETE); |
| 1911 STATE_CASE(STATE_SPDY_SEND_REQUEST); |
| 1912 STATE_CASE(STATE_SPDY_SEND_REQUEST_COMPLETE); |
| 1913 STATE_CASE(STATE_SPDY_READ_HEADERS); |
| 1914 STATE_CASE(STATE_SPDY_READ_HEADERS_COMPLETE); |
| 1915 STATE_CASE(STATE_SPDY_READ_BODY); |
| 1916 STATE_CASE(STATE_SPDY_READ_BODY_COMPLETE); |
| 1822 STATE_CASE(STATE_NONE); | 1917 STATE_CASE(STATE_NONE); |
| 1823 default: | 1918 default: |
| 1824 description = StringPrintf("Unknown state 0x%08X (%u)", state, state); | 1919 description = StringPrintf("Unknown state 0x%08X (%u)", state, state); |
| 1825 break; | 1920 break; |
| 1826 } | 1921 } |
| 1827 return description; | 1922 return description; |
| 1828 } | 1923 } |
| 1829 | 1924 |
| 1830 // TODO(gavinp): re-adjust this once SPDY v3 has three priority bits, | 1925 // TODO(gavinp): re-adjust this once SPDY v3 has three priority bits, |
| 1831 // eliminating the need for this folding. | 1926 // eliminating the need for this folding. |
| 1832 int ConvertRequestPriorityToSpdyPriority(const RequestPriority priority) { | 1927 int ConvertRequestPriorityToSpdyPriority(const RequestPriority priority) { |
| 1833 DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES); | 1928 DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES); |
| 1834 switch (priority) { | 1929 switch (priority) { |
| 1835 case LOWEST: | 1930 case LOWEST: |
| 1836 return SPDY_PRIORITY_LOWEST-1; | 1931 return SPDY_PRIORITY_LOWEST-1; |
| 1837 case IDLE: | 1932 case IDLE: |
| 1838 return SPDY_PRIORITY_LOWEST; | 1933 return SPDY_PRIORITY_LOWEST; |
| 1839 default: | 1934 default: |
| 1840 return priority; | 1935 return priority; |
| 1841 } | 1936 } |
| 1842 } | 1937 } |
| 1843 | 1938 |
| 1844 | 1939 |
| 1845 | 1940 |
| 1846 #undef STATE_CASE | 1941 #undef STATE_CASE |
| 1847 | 1942 |
| 1848 } // namespace net | 1943 } // namespace net |
| OLD | NEW |