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