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; |
| 717 spdy_session_ = |
| 718 session_->spdy_session_pool()->Get(pair, session_, net_log_); |
752 return OK; | 719 return OK; |
753 } | 720 } |
754 | 721 |
755 // Build the string used to uniquely identify connections of this type. | 722 // Build the string used to uniquely identify connections of this type. |
756 // Determine the host and port to connect to. | 723 // Determine the host and port to connect to. |
757 std::string connection_group = endpoint_.ToString(); | 724 std::string connection_group = endpoint_.ToString(); |
758 DCHECK(!connection_group.empty()); | 725 DCHECK(!connection_group.empty()); |
759 | 726 |
760 if (using_ssl_) | 727 if (using_ssl_) |
761 connection_group = StringPrintf("ssl/%s", connection_group.c_str()); | 728 connection_group = StringPrintf("ssl/%s", connection_group.c_str()); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 if (!reused_socket_) { | 910 if (!reused_socket_) { |
944 if (using_spdy_) | 911 if (using_spdy_) |
945 UpdateConnectionTypeHistograms(CONNECTION_SPDY); | 912 UpdateConnectionTypeHistograms(CONNECTION_SPDY); |
946 else | 913 else |
947 UpdateConnectionTypeHistograms(CONNECTION_HTTP); | 914 UpdateConnectionTypeHistograms(CONNECTION_HTTP); |
948 } | 915 } |
949 | 916 |
950 if (!using_ssl_) { | 917 if (!using_ssl_) { |
951 DCHECK_EQ(OK, result); | 918 DCHECK_EQ(OK, result); |
952 if (using_spdy_) | 919 if (using_spdy_) |
953 next_state_ = STATE_SPDY_GET_STREAM; | 920 next_state_ = STATE_INIT_STREAM; |
954 else | 921 else |
955 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; | 922 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; |
956 return result; | 923 return result; |
957 } | 924 } |
958 } | 925 } |
959 | 926 |
960 // Handle SSL errors below. | 927 // Handle SSL errors below. |
961 DCHECK(using_ssl_); | 928 DCHECK(using_ssl_); |
962 DCHECK(ssl_started); | 929 DCHECK(ssl_started); |
963 if (IsCertificateError(result)) { | 930 if (IsCertificateError(result)) { |
(...skipping 16 matching lines...) Expand all Loading... |
980 response_.cert_request_info = | 947 response_.cert_request_info = |
981 connection_->ssl_error_response_info().cert_request_info; | 948 connection_->ssl_error_response_info().cert_request_info; |
982 return HandleCertificateRequest(result); | 949 return HandleCertificateRequest(result); |
983 } | 950 } |
984 if (result < 0) | 951 if (result < 0) |
985 return HandleSSLHandshakeError(result); | 952 return HandleSSLHandshakeError(result); |
986 | 953 |
987 if (using_spdy_) { | 954 if (using_spdy_) { |
988 UpdateConnectionTypeHistograms(CONNECTION_SPDY); | 955 UpdateConnectionTypeHistograms(CONNECTION_SPDY); |
989 // TODO(cbentzel): Add auth support to spdy. See http://crbug.com/46620 | 956 // TODO(cbentzel): Add auth support to spdy. See http://crbug.com/46620 |
990 next_state_ = STATE_SPDY_GET_STREAM; | 957 next_state_ = STATE_INIT_STREAM; |
991 } else { | 958 } else { |
992 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; | 959 next_state_ = STATE_GENERATE_PROXY_AUTH_TOKEN; |
993 } | 960 } |
994 return OK; | 961 return OK; |
995 } | 962 } |
996 | 963 |
| 964 int HttpNetworkTransaction::DoInitStream() { |
| 965 next_state_ = STATE_INIT_STREAM_COMPLETE; |
| 966 |
| 967 if (!using_spdy_) { |
| 968 stream_.reset(new HttpBasicStream(connection_.get())); |
| 969 return stream_->InitializeStream(request_, net_log_, &io_callback_); |
| 970 } |
| 971 |
| 972 CHECK(!stream_.get()); |
| 973 |
| 974 const scoped_refptr<SpdySessionPool> spdy_pool = |
| 975 session_->spdy_session_pool(); |
| 976 |
| 977 HostPortProxyPair pair(endpoint_, proxy_info_.ToPacString()); |
| 978 if (!spdy_session_.get()) { |
| 979 // SPDY can be negotiated using the TLS next protocol negotiation (NPN) |
| 980 // extension, or just directly using SSL. Either way, |connection_| must |
| 981 // contain an SSLClientSocket. |
| 982 CHECK(connection_->socket()); |
| 983 int error = spdy_pool->GetSpdySessionFromSocket( |
| 984 pair, session_, connection_.release(), net_log_, |
| 985 spdy_certificate_error_, &spdy_session_, using_ssl_); |
| 986 if (error != OK) |
| 987 return error; |
| 988 } |
| 989 CHECK(spdy_session_.get()); |
| 990 if (spdy_session_->IsClosed()) |
| 991 return ERR_CONNECTION_CLOSED; |
| 992 |
| 993 headers_valid_ = false; |
| 994 |
| 995 stream_.reset(new SpdyHttpStream(spdy_session_.release())); |
| 996 return stream_->InitializeStream(request_, net_log_, &io_callback_); |
| 997 } |
| 998 |
| 999 int HttpNetworkTransaction::DoInitStreamComplete(int result) { |
| 1000 if (result < 0) |
| 1001 return result; |
| 1002 |
| 1003 next_state_ = STATE_SEND_REQUEST; |
| 1004 return OK; |
| 1005 } |
| 1006 |
997 int HttpNetworkTransaction::DoRestartTunnelAuth() { | 1007 int HttpNetworkTransaction::DoRestartTunnelAuth() { |
998 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; | 1008 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; |
999 HttpProxyClientSocket* http_proxy_socket = | 1009 HttpProxyClientSocket* http_proxy_socket = |
1000 static_cast<HttpProxyClientSocket*>(connection_->socket()); | 1010 static_cast<HttpProxyClientSocket*>(connection_->socket()); |
1001 return http_proxy_socket->RestartWithAuth(&io_callback_); | 1011 return http_proxy_socket->RestartWithAuth(&io_callback_); |
1002 } | 1012 } |
1003 | 1013 |
1004 int HttpNetworkTransaction::DoRestartTunnelAuthComplete(int result) { | 1014 int HttpNetworkTransaction::DoRestartTunnelAuthComplete(int result) { |
1005 if (result == ERR_PROXY_AUTH_REQUESTED) | 1015 if (result == ERR_PROXY_AUTH_REQUESTED) |
1006 return HandleTunnelAuthFailure(result); | 1016 return HandleTunnelAuthFailure(result); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 if (!ShouldApplyServerAuth()) | 1060 if (!ShouldApplyServerAuth()) |
1051 return OK; | 1061 return OK; |
1052 return auth_controllers_[target]->MaybeGenerateAuthToken(request_, | 1062 return auth_controllers_[target]->MaybeGenerateAuthToken(request_, |
1053 &io_callback_, | 1063 &io_callback_, |
1054 net_log_); | 1064 net_log_); |
1055 } | 1065 } |
1056 | 1066 |
1057 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { | 1067 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { |
1058 DCHECK_NE(ERR_IO_PENDING, rv); | 1068 DCHECK_NE(ERR_IO_PENDING, rv); |
1059 if (rv == OK) | 1069 if (rv == OK) |
1060 next_state_ = STATE_SEND_REQUEST; | 1070 next_state_ = STATE_INIT_STREAM; |
1061 return rv; | 1071 return rv; |
1062 } | 1072 } |
1063 | 1073 |
1064 int HttpNetworkTransaction::DoSendRequest() { | 1074 int HttpNetworkTransaction::DoSendRequest() { |
1065 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1075 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
1066 | 1076 |
1067 UploadDataStream* request_body = NULL; | 1077 UploadDataStream* request_body = NULL; |
1068 if (request_->upload_data) { | 1078 if (request_->upload_data) { |
1069 int error_code; | 1079 int error_code; |
1070 request_body = UploadDataStream::Create(request_->upload_data, &error_code); | 1080 request_body = UploadDataStream::Create(request_->upload_data, &error_code); |
1071 if (!request_body) | 1081 if (!request_body) |
1072 return error_code; | 1082 return error_code; |
1073 } | 1083 } |
1074 | 1084 |
1075 // This is constructed lazily (instead of within our Start method), so that | 1085 // This is constructed lazily (instead of within our Start method), so that |
1076 // we have proxy info available. | 1086 // we have proxy info available. |
1077 if (request_headers_.empty()) { | 1087 if (request_headers_.empty() && !using_spdy_) { |
1078 // Figure out if we can/should add Proxy-Authentication & Authentication | 1088 // Figure out if we can/should add Proxy-Authentication & Authentication |
1079 // headers. | 1089 // headers. |
1080 HttpRequestHeaders authorization_headers; | 1090 HttpRequestHeaders authorization_headers; |
1081 bool have_proxy_auth = (ShouldApplyProxyAuth() && | 1091 bool have_proxy_auth = (ShouldApplyProxyAuth() && |
1082 HaveAuth(HttpAuth::AUTH_PROXY)); | 1092 HaveAuth(HttpAuth::AUTH_PROXY)); |
1083 bool have_server_auth = (ShouldApplyServerAuth() && | 1093 bool have_server_auth = (ShouldApplyServerAuth() && |
1084 HaveAuth(HttpAuth::AUTH_SERVER)); | 1094 HaveAuth(HttpAuth::AUTH_SERVER)); |
1085 if (have_proxy_auth) | 1095 if (have_proxy_auth) |
1086 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( | 1096 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( |
1087 &authorization_headers); | 1097 &authorization_headers); |
(...skipping 12 matching lines...) Expand all Loading... |
1100 if (net_log_.HasListener()) { | 1110 if (net_log_.HasListener()) { |
1101 net_log_.AddEvent( | 1111 net_log_.AddEvent( |
1102 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | 1112 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
1103 new NetLogHttpRequestParameter(request_line, request_headers)); | 1113 new NetLogHttpRequestParameter(request_line, request_headers)); |
1104 } | 1114 } |
1105 | 1115 |
1106 request_headers_ = request_line + request_headers.ToString(); | 1116 request_headers_ = request_line + request_headers.ToString(); |
1107 } | 1117 } |
1108 | 1118 |
1109 headers_valid_ = false; | 1119 headers_valid_ = false; |
1110 http_stream_.reset(new HttpBasicStream(connection_.get())); | 1120 return stream_->SendRequest(request_headers_, request_body, &response_, |
1111 http_stream_->InitializeStream(request_, net_log_, NULL); | 1121 &io_callback_); |
1112 return http_stream_->SendRequest(request_headers_, request_body, &response_, | |
1113 &io_callback_); | |
1114 } | 1122 } |
1115 | 1123 |
1116 int HttpNetworkTransaction::DoSendRequestComplete(int result) { | 1124 int HttpNetworkTransaction::DoSendRequestComplete(int result) { |
1117 if (result < 0) | 1125 if (result < 0) |
1118 return HandleIOError(result); | 1126 return HandleIOError(result); |
1119 next_state_ = STATE_READ_HEADERS; | 1127 next_state_ = STATE_READ_HEADERS; |
1120 return OK; | 1128 return OK; |
1121 } | 1129 } |
1122 | 1130 |
1123 int HttpNetworkTransaction::DoReadHeaders() { | 1131 int HttpNetworkTransaction::DoReadHeaders() { |
1124 next_state_ = STATE_READ_HEADERS_COMPLETE; | 1132 next_state_ = STATE_READ_HEADERS_COMPLETE; |
1125 return http_stream_->ReadResponseHeaders(&io_callback_); | 1133 return stream_->ReadResponseHeaders(&io_callback_); |
1126 } | 1134 } |
1127 | 1135 |
1128 int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() { | 1136 int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() { |
1129 if (!response_.headers) { | 1137 if (!response_.headers) { |
1130 // The connection was closed before any data was sent. Likely an error | 1138 // The connection was closed before any data was sent. Likely an error |
1131 // rather than empty HTTP/0.9 response. | 1139 // rather than empty HTTP/0.9 response. |
1132 return ERR_EMPTY_RESPONSE; | 1140 return ERR_EMPTY_RESPONSE; |
1133 } | 1141 } |
1134 | 1142 |
1135 return OK; | 1143 return OK; |
1136 } | 1144 } |
1137 | 1145 |
1138 int HttpNetworkTransaction::DoReadHeadersComplete(int result) { | 1146 int HttpNetworkTransaction::DoReadHeadersComplete(int result) { |
| 1147 if (using_spdy_) { |
| 1148 // TODO(willchan): Flesh out the support for HTTP authentication here. |
| 1149 if (result < 0) |
| 1150 return HandleIOError(result); |
| 1151 |
| 1152 if (result == OK) |
| 1153 headers_valid_ = true; |
| 1154 |
| 1155 LogTransactionConnectedMetrics(); |
| 1156 return result; |
| 1157 } |
| 1158 |
1139 // We can get a certificate error or ERR_SSL_CLIENT_AUTH_CERT_NEEDED here | 1159 // We can get a certificate error or ERR_SSL_CLIENT_AUTH_CERT_NEEDED here |
1140 // due to SSL renegotiation. | 1160 // due to SSL renegotiation. |
1141 if (using_ssl_) { | 1161 if (using_ssl_) { |
1142 if (IsCertificateError(result)) { | 1162 if (IsCertificateError(result)) { |
1143 // We don't handle a certificate error during SSL renegotiation, so we | 1163 // We don't handle a certificate error during SSL renegotiation, so we |
1144 // have to return an error that's not in the certificate error range | 1164 // have to return an error that's not in the certificate error range |
1145 // (-2xx). | 1165 // (-2xx). |
1146 LOG(ERROR) << "Got a server certificate with error " << result | 1166 LOG(ERROR) << "Got a server certificate with error " << result |
1147 << " during SSL renegotiation"; | 1167 << " during SSL renegotiation"; |
1148 result = ERR_CERT_ERROR_IN_SSL_RENEGOTIATION; | 1168 result = ERR_CERT_ERROR_IN_SSL_RENEGOTIATION; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 ssl_socket->GetSSLInfo(&response_.ssl_info); | 1254 ssl_socket->GetSSLInfo(&response_.ssl_info); |
1235 } | 1255 } |
1236 | 1256 |
1237 headers_valid_ = true; | 1257 headers_valid_ = true; |
1238 return OK; | 1258 return OK; |
1239 } | 1259 } |
1240 | 1260 |
1241 int HttpNetworkTransaction::DoReadBody() { | 1261 int HttpNetworkTransaction::DoReadBody() { |
1242 DCHECK(read_buf_); | 1262 DCHECK(read_buf_); |
1243 DCHECK_GT(read_buf_len_, 0); | 1263 DCHECK_GT(read_buf_len_, 0); |
1244 DCHECK(connection_->is_initialized()); | 1264 if (!using_spdy_) |
| 1265 DCHECK(connection_->is_initialized()); |
1245 | 1266 |
1246 next_state_ = STATE_READ_BODY_COMPLETE; | 1267 next_state_ = STATE_READ_BODY_COMPLETE; |
1247 return http_stream_->ReadResponseBody(read_buf_, read_buf_len_, | 1268 return stream_->ReadResponseBody(read_buf_, read_buf_len_, &io_callback_); |
1248 &io_callback_); | |
1249 } | 1269 } |
1250 | 1270 |
1251 int HttpNetworkTransaction::DoReadBodyComplete(int result) { | 1271 int HttpNetworkTransaction::DoReadBodyComplete(int result) { |
1252 // We are done with the Read call. | 1272 if (!using_spdy_) { |
1253 bool done = false, keep_alive = false; | 1273 // We are done with the Read call. |
1254 if (result <= 0) | 1274 bool done = false, keep_alive = false; |
1255 done = true; | 1275 if (result <= 0) |
| 1276 done = true; |
1256 | 1277 |
1257 if (http_stream_->IsResponseBodyComplete()) { | 1278 if (stream_->IsResponseBodyComplete()) { |
1258 done = true; | 1279 done = true; |
1259 if (http_stream_->CanFindEndOfResponse()) | 1280 if (stream_->CanFindEndOfResponse()) |
1260 keep_alive = GetResponseHeaders()->IsKeepAlive(); | 1281 keep_alive = GetResponseHeaders()->IsKeepAlive(); |
1261 } | 1282 } |
1262 | 1283 |
1263 // Clean up connection_->if we are done. | 1284 // Clean up connection_->if we are done. |
1264 if (done) { | 1285 if (done) { |
1265 LogTransactionMetrics(); | 1286 LogTransactionMetrics(); |
1266 if (!keep_alive) | 1287 if (!keep_alive) |
1267 connection_->socket()->Disconnect(); | 1288 connection_->socket()->Disconnect(); |
1268 connection_->Reset(); | 1289 connection_->Reset(); |
1269 // The next Read call will return 0 (EOF). | 1290 // The next Read call will return 0 (EOF). |
| 1291 } |
| 1292 } else { |
| 1293 if (result <= 0) |
| 1294 stream_.reset(); |
1270 } | 1295 } |
1271 | 1296 |
1272 // Clear these to avoid leaving around old state. | 1297 // Clear these to avoid leaving around old state. |
1273 read_buf_ = NULL; | 1298 read_buf_ = NULL; |
1274 read_buf_len_ = 0; | 1299 read_buf_len_ = 0; |
1275 | 1300 |
1276 return result; | 1301 return result; |
1277 } | 1302 } |
1278 | 1303 |
1279 int HttpNetworkTransaction::DoDrainBodyForAuthRestart() { | 1304 int HttpNetworkTransaction::DoDrainBodyForAuthRestart() { |
1280 // This method differs from DoReadBody only in the next_state_. So we just | 1305 // This method differs from DoReadBody only in the next_state_. So we just |
1281 // call DoReadBody and override the next_state_. Perhaps there is a more | 1306 // call DoReadBody and override the next_state_. Perhaps there is a more |
1282 // elegant way for these two methods to share code. | 1307 // elegant way for these two methods to share code. |
1283 int rv = DoReadBody(); | 1308 int rv = DoReadBody(); |
1284 DCHECK(next_state_ == STATE_READ_BODY_COMPLETE); | 1309 DCHECK(next_state_ == STATE_READ_BODY_COMPLETE); |
1285 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE; | 1310 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE; |
1286 return rv; | 1311 return rv; |
1287 } | 1312 } |
1288 | 1313 |
1289 // TODO(wtc): This method and the DoReadBodyComplete method are almost | 1314 // TODO(wtc): This method and the DoReadBodyComplete method are almost |
1290 // the same. Figure out a good way for these two methods to share code. | 1315 // the same. Figure out a good way for these two methods to share code. |
1291 int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { | 1316 int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { |
1292 // keep_alive defaults to true because the very reason we're draining the | 1317 // keep_alive defaults to true because the very reason we're draining the |
1293 // response body is to reuse the connection for auth restart. | 1318 // response body is to reuse the connection for auth restart. |
1294 bool done = false, keep_alive = true; | 1319 bool done = false, keep_alive = true; |
1295 if (result < 0) { | 1320 if (result < 0) { |
1296 // Error or closed connection while reading the socket. | 1321 // Error or closed connection while reading the socket. |
1297 done = true; | 1322 done = true; |
1298 keep_alive = false; | 1323 keep_alive = false; |
1299 } else if (http_stream_->IsResponseBodyComplete()) { | 1324 } else if (stream_->IsResponseBodyComplete()) { |
1300 done = true; | 1325 done = true; |
1301 } | 1326 } |
1302 | 1327 |
1303 if (done) { | 1328 if (done) { |
1304 DidDrainBodyForAuthRestart(keep_alive); | 1329 DidDrainBodyForAuthRestart(keep_alive); |
1305 } else { | 1330 } else { |
1306 // Keep draining. | 1331 // Keep draining. |
1307 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; | 1332 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; |
1308 } | 1333 } |
1309 | 1334 |
1310 return OK; | 1335 return OK; |
1311 } | 1336 } |
1312 | 1337 |
1313 int HttpNetworkTransaction::DoSpdyGetStream() { | |
1314 next_state_ = STATE_SPDY_GET_STREAM_COMPLETE; | |
1315 CHECK(!spdy_http_stream_.get()); | |
1316 | |
1317 // First we get a SPDY session. Theoretically, we've just negotiated one, but | |
1318 // if one already exists, then screw it, use the existing one! Otherwise, | |
1319 // use the existing TCP socket. | |
1320 | |
1321 const scoped_refptr<SpdySessionPool> spdy_pool = | |
1322 session_->spdy_session_pool(); | |
1323 scoped_refptr<SpdySession> spdy_session; | |
1324 | |
1325 HostPortProxyPair pair(endpoint_, proxy_info_.ToPacString()); | |
1326 if (spdy_pool->HasSession(pair)) { | |
1327 spdy_session = spdy_pool->Get(pair, session_, net_log_); | |
1328 } else { | |
1329 if(using_ssl_) { | |
1330 // SPDY can be negotiated using the TLS next protocol negotiation (NPN) | |
1331 // extension, or just directly using SSL. Either way, |connection_| must | |
1332 // contain an SSLClientSocket. | |
1333 CHECK(connection_->socket()); | |
1334 int error = spdy_pool->GetSpdySessionFromSocket( | |
1335 pair, session_, connection_.release(), net_log_, | |
1336 spdy_certificate_error_, &spdy_session, true); | |
1337 if (error != OK) | |
1338 return error; | |
1339 } | |
1340 else { | |
1341 // We may want SPDY without SSL | |
1342 int error = spdy_pool->GetSpdySessionFromSocket( | |
1343 pair, session_, connection_.release(), net_log_, | |
1344 spdy_certificate_error_, &spdy_session, false); | |
1345 if (error != OK) | |
1346 return error; | |
1347 } | |
1348 } | |
1349 | |
1350 CHECK(spdy_session.get()); | |
1351 if (spdy_session->IsClosed()) | |
1352 return ERR_CONNECTION_CLOSED; | |
1353 | |
1354 headers_valid_ = false; | |
1355 | |
1356 spdy_http_stream_.reset(new SpdyHttpStream(spdy_session)); | |
1357 return spdy_http_stream_->InitializeStream(request_, net_log_, &io_callback_); | |
1358 } | |
1359 | |
1360 int HttpNetworkTransaction::DoSpdyGetStreamComplete(int result) { | |
1361 if (result < 0) | |
1362 return result; | |
1363 | |
1364 next_state_ = STATE_SPDY_SEND_REQUEST; | |
1365 return OK; | |
1366 } | |
1367 | |
1368 int HttpNetworkTransaction::DoSpdySendRequest() { | |
1369 next_state_ = STATE_SPDY_SEND_REQUEST_COMPLETE; | |
1370 | |
1371 UploadDataStream* upload_data_stream = NULL; | |
1372 if (request_->upload_data) { | |
1373 int error_code = OK; | |
1374 upload_data_stream = UploadDataStream::Create(request_->upload_data, | |
1375 &error_code); | |
1376 if (!upload_data_stream) | |
1377 return error_code; | |
1378 } | |
1379 return spdy_http_stream_->SendRequest(request_headers_, upload_data_stream, | |
1380 &response_, &io_callback_); | |
1381 } | |
1382 | |
1383 int HttpNetworkTransaction::DoSpdySendRequestComplete(int result) { | |
1384 if (result < 0) | |
1385 return HandleIOError(result); | |
1386 | |
1387 next_state_ = STATE_SPDY_READ_HEADERS; | |
1388 return OK; | |
1389 } | |
1390 | |
1391 int HttpNetworkTransaction::DoSpdyReadHeaders() { | |
1392 next_state_ = STATE_SPDY_READ_HEADERS_COMPLETE; | |
1393 return spdy_http_stream_->ReadResponseHeaders(&io_callback_); | |
1394 } | |
1395 | |
1396 int HttpNetworkTransaction::DoSpdyReadHeadersComplete(int result) { | |
1397 // TODO(willchan): Flesh out the support for HTTP authentication here. | |
1398 if (result < 0) | |
1399 return HandleIOError(result); | |
1400 | |
1401 if (result == OK) | |
1402 headers_valid_ = true; | |
1403 | |
1404 LogTransactionConnectedMetrics(); | |
1405 return result; | |
1406 } | |
1407 | |
1408 int HttpNetworkTransaction::DoSpdyReadBody() { | |
1409 next_state_ = STATE_SPDY_READ_BODY_COMPLETE; | |
1410 | |
1411 return spdy_http_stream_->ReadResponseBody( | |
1412 read_buf_, read_buf_len_, &io_callback_); | |
1413 } | |
1414 | |
1415 int HttpNetworkTransaction::DoSpdyReadBodyComplete(int result) { | |
1416 read_buf_ = NULL; | |
1417 read_buf_len_ = 0; | |
1418 | |
1419 if (result <= 0) | |
1420 spdy_http_stream_.reset(); | |
1421 | |
1422 return result; | |
1423 } | |
1424 | |
1425 void HttpNetworkTransaction::LogHttpConnectedMetrics( | 1338 void HttpNetworkTransaction::LogHttpConnectedMetrics( |
1426 const ClientSocketHandle& handle) { | 1339 const ClientSocketHandle& handle) { |
1427 UMA_HISTOGRAM_ENUMERATION("Net.HttpSocketType", handle.reuse_type(), | 1340 UMA_HISTOGRAM_ENUMERATION("Net.HttpSocketType", handle.reuse_type(), |
1428 ClientSocketHandle::NUM_TYPES); | 1341 ClientSocketHandle::NUM_TYPES); |
1429 | 1342 |
1430 switch (handle.reuse_type()) { | 1343 switch (handle.reuse_type()) { |
1431 case ClientSocketHandle::UNUSED: | 1344 case ClientSocketHandle::UNUSED: |
1432 UMA_HISTOGRAM_CUSTOM_TIMES("Net.HttpConnectionLatency", | 1345 UMA_HISTOGRAM_CUSTOM_TIMES("Net.HttpConnectionLatency", |
1433 handle.setup_time(), | 1346 handle.setup_time(), |
1434 base::TimeDelta::FromMilliseconds(1), | 1347 base::TimeDelta::FromMilliseconds(1), |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 } | 1606 } |
1694 break; | 1607 break; |
1695 } | 1608 } |
1696 return error; | 1609 return error; |
1697 } | 1610 } |
1698 | 1611 |
1699 void HttpNetworkTransaction::ResetStateForRestart() { | 1612 void HttpNetworkTransaction::ResetStateForRestart() { |
1700 pending_auth_target_ = HttpAuth::AUTH_NONE; | 1613 pending_auth_target_ = HttpAuth::AUTH_NONE; |
1701 read_buf_ = NULL; | 1614 read_buf_ = NULL; |
1702 read_buf_len_ = 0; | 1615 read_buf_len_ = 0; |
1703 http_stream_.reset(); | 1616 stream_.reset(); |
1704 headers_valid_ = false; | 1617 headers_valid_ = false; |
1705 request_headers_.clear(); | 1618 request_headers_.clear(); |
1706 response_ = HttpResponseInfo(); | 1619 response_ = HttpResponseInfo(); |
1707 } | 1620 } |
1708 | 1621 |
1709 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { | 1622 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { |
1710 return response_.headers; | 1623 return response_.headers; |
1711 } | 1624 } |
1712 | 1625 |
1713 bool HttpNetworkTransaction::ShouldResendRequest(int error) const { | 1626 bool HttpNetworkTransaction::ShouldResendRequest(int error) const { |
1714 if (using_spdy_ && spdy_http_stream_ != NULL) | 1627 if (using_spdy_ && stream_ != NULL) |
1715 return spdy_http_stream_->ShouldResendFailedRequest(error); | 1628 return static_cast<SpdyHttpStream *>(stream_.get())-> |
| 1629 ShouldResendFailedRequest(error); |
1716 | 1630 |
1717 // NOTE: we resend a request only if we reused a keep-alive connection. | 1631 // NOTE: we resend a request only if we reused a keep-alive connection. |
1718 // This automatically prevents an infinite resend loop because we'll run | 1632 // This automatically prevents an infinite resend loop because we'll run |
1719 // out of the cached keep-alive connections eventually. | 1633 // out of the cached keep-alive connections eventually. |
1720 if (!connection_->ShouldResendFailedRequest(error) || | 1634 if (!connection_->ShouldResendFailedRequest(error) || |
1721 GetResponseHeaders()) { // We have received some response headers. | 1635 GetResponseHeaders()) { // We have received some response headers. |
1722 return false; | 1636 return false; |
1723 } | 1637 } |
1724 return true; | 1638 return true; |
1725 } | 1639 } |
1726 | 1640 |
1727 void HttpNetworkTransaction::ResetConnectionAndRequestForResend() { | 1641 void HttpNetworkTransaction::ResetConnectionAndRequestForResend() { |
1728 // Note: When using SPDY we may not own a connection. | 1642 // Note: When using SPDY we may not own a connection. |
1729 if (connection_.get()) { | 1643 if (connection_.get()) { |
1730 if (connection_->socket()) | 1644 if (connection_->socket()) |
1731 connection_->socket()->Disconnect(); | 1645 connection_->socket()->Disconnect(); |
1732 connection_->Reset(); | 1646 connection_->Reset(); |
1733 } else { | 1647 } else { |
1734 DCHECK(using_spdy_); | 1648 DCHECK(using_spdy_); |
1735 connection_.reset(new ClientSocketHandle); | 1649 connection_.reset(new ClientSocketHandle); |
1736 } | 1650 } |
1737 | 1651 |
1738 // We need to clear request_headers_ because it contains the real request | 1652 // We need to clear request_headers_ because it contains the real request |
1739 // headers, but we may need to resend the CONNECT request first to recreate | 1653 // headers, but we may need to resend the CONNECT request first to recreate |
1740 // the SSL tunnel. | 1654 // the SSL tunnel. |
1741 | 1655 |
1742 spdy_http_stream_.reset(NULL); | 1656 stream_.reset(NULL); |
1743 | 1657 |
1744 request_headers_.clear(); | 1658 request_headers_.clear(); |
1745 next_state_ = STATE_INIT_CONNECTION; // Resend the request. | 1659 next_state_ = STATE_INIT_CONNECTION; // Resend the request. |
1746 } | 1660 } |
1747 | 1661 |
1748 int HttpNetworkTransaction::ReconsiderProxyAfterError(int error) { | 1662 int HttpNetworkTransaction::ReconsiderProxyAfterError(int error) { |
1749 DCHECK(!pac_request_); | 1663 DCHECK(!pac_request_); |
1750 | 1664 |
1751 // A failure to resolve the hostname or any error related to establishing a | 1665 // A failure to resolve the hostname or any error related to establishing a |
1752 // TCP connection could be grounds for trying a new proxy configuration. | 1666 // TCP connection could be grounds for trying a new proxy configuration. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 description = StringPrintf("%s (0x%08X)", #s, s); \ | 1795 description = StringPrintf("%s (0x%08X)", #s, s); \ |
1882 break | 1796 break |
1883 | 1797 |
1884 std::string HttpNetworkTransaction::DescribeState(State state) { | 1798 std::string HttpNetworkTransaction::DescribeState(State state) { |
1885 std::string description; | 1799 std::string description; |
1886 switch (state) { | 1800 switch (state) { |
1887 STATE_CASE(STATE_RESOLVE_PROXY); | 1801 STATE_CASE(STATE_RESOLVE_PROXY); |
1888 STATE_CASE(STATE_RESOLVE_PROXY_COMPLETE); | 1802 STATE_CASE(STATE_RESOLVE_PROXY_COMPLETE); |
1889 STATE_CASE(STATE_INIT_CONNECTION); | 1803 STATE_CASE(STATE_INIT_CONNECTION); |
1890 STATE_CASE(STATE_INIT_CONNECTION_COMPLETE); | 1804 STATE_CASE(STATE_INIT_CONNECTION_COMPLETE); |
| 1805 STATE_CASE(STATE_INIT_STREAM); |
| 1806 STATE_CASE(STATE_INIT_STREAM_COMPLETE); |
1891 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN); | 1807 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN); |
1892 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE); | 1808 STATE_CASE(STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE); |
1893 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN); | 1809 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN); |
1894 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE); | 1810 STATE_CASE(STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE); |
1895 STATE_CASE(STATE_SEND_REQUEST); | 1811 STATE_CASE(STATE_SEND_REQUEST); |
1896 STATE_CASE(STATE_SEND_REQUEST_COMPLETE); | 1812 STATE_CASE(STATE_SEND_REQUEST_COMPLETE); |
1897 STATE_CASE(STATE_READ_HEADERS); | 1813 STATE_CASE(STATE_READ_HEADERS); |
1898 STATE_CASE(STATE_READ_HEADERS_COMPLETE); | 1814 STATE_CASE(STATE_READ_HEADERS_COMPLETE); |
1899 STATE_CASE(STATE_READ_BODY); | 1815 STATE_CASE(STATE_READ_BODY); |
1900 STATE_CASE(STATE_READ_BODY_COMPLETE); | 1816 STATE_CASE(STATE_READ_BODY_COMPLETE); |
1901 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); | 1817 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); |
1902 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); | 1818 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); |
1903 STATE_CASE(STATE_SPDY_GET_STREAM); | |
1904 STATE_CASE(STATE_SPDY_GET_STREAM_COMPLETE); | |
1905 STATE_CASE(STATE_SPDY_SEND_REQUEST); | |
1906 STATE_CASE(STATE_SPDY_SEND_REQUEST_COMPLETE); | |
1907 STATE_CASE(STATE_SPDY_READ_HEADERS); | |
1908 STATE_CASE(STATE_SPDY_READ_HEADERS_COMPLETE); | |
1909 STATE_CASE(STATE_SPDY_READ_BODY); | |
1910 STATE_CASE(STATE_SPDY_READ_BODY_COMPLETE); | |
1911 STATE_CASE(STATE_NONE); | 1819 STATE_CASE(STATE_NONE); |
1912 default: | 1820 default: |
1913 description = StringPrintf("Unknown state 0x%08X (%u)", state, state); | 1821 description = StringPrintf("Unknown state 0x%08X (%u)", state, state); |
1914 break; | 1822 break; |
1915 } | 1823 } |
1916 return description; | 1824 return description; |
1917 } | 1825 } |
1918 | 1826 |
1919 // TODO(gavinp): re-adjust this once SPDY v3 has three priority bits, | 1827 // TODO(gavinp): re-adjust this once SPDY v3 has three priority bits, |
1920 // eliminating the need for this folding. | 1828 // eliminating the need for this folding. |
1921 int ConvertRequestPriorityToSpdyPriority(const RequestPriority priority) { | 1829 int ConvertRequestPriorityToSpdyPriority(const RequestPriority priority) { |
1922 DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES); | 1830 DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES); |
1923 switch (priority) { | 1831 switch (priority) { |
1924 case LOWEST: | 1832 case LOWEST: |
1925 return SPDY_PRIORITY_LOWEST-1; | 1833 return SPDY_PRIORITY_LOWEST-1; |
1926 case IDLE: | 1834 case IDLE: |
1927 return SPDY_PRIORITY_LOWEST; | 1835 return SPDY_PRIORITY_LOWEST; |
1928 default: | 1836 default: |
1929 return priority; | 1837 return priority; |
1930 } | 1838 } |
1931 } | 1839 } |
1932 | 1840 |
1933 | 1841 |
1934 | 1842 |
1935 #undef STATE_CASE | 1843 #undef STATE_CASE |
1936 | 1844 |
1937 } // namespace net | 1845 } // namespace net |
OLD | NEW |