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_stream_request.h" | 5 #include "net/http/http_stream_request.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/connection_type_histograms.h" | 10 #include "net/base/connection_type_histograms.h" |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 using_spdy_ = false; | 420 using_spdy_ = false; |
421 | 421 |
422 // Check first if we have a spdy session for this group. If so, then go | 422 // Check first if we have a spdy session for this group. If so, then go |
423 // straight to using that. | 423 // straight to using that. |
424 HostPortProxyPair pair(endpoint_, proxy_info()->proxy_server()); | 424 HostPortProxyPair pair(endpoint_, proxy_info()->proxy_server()); |
425 if (session_->spdy_session_pool()->HasSession(pair)) { | 425 if (session_->spdy_session_pool()->HasSession(pair)) { |
426 using_spdy_ = true; | 426 using_spdy_ = true; |
427 next_state_ = STATE_CREATE_STREAM; | 427 next_state_ = STATE_CREATE_STREAM; |
428 return OK; | 428 return OK; |
429 } | 429 } |
| 430 // Check next if we have a spdy session for this proxy. If so, then go |
| 431 // straight to using that. |
| 432 if (proxy_info()->is_https()) { |
| 433 HostPortProxyPair proxy(proxy_info()->proxy_server().host_port_pair(), |
| 434 proxy_info()->proxy_server()); |
| 435 if (session_->spdy_session_pool()->HasSession(proxy)) { |
| 436 using_spdy_ = true; |
| 437 next_state_ = STATE_CREATE_STREAM; |
| 438 return OK; |
| 439 } |
| 440 } |
430 | 441 |
431 // Build the string used to uniquely identify connections of this type. | 442 // Build the string used to uniquely identify connections of this type. |
432 // Determine the host and port to connect to. | 443 // Determine the host and port to connect to. |
433 std::string connection_group = endpoint_.ToString(); | 444 std::string connection_group = endpoint_.ToString(); |
434 DCHECK(!connection_group.empty()); | 445 DCHECK(!connection_group.empty()); |
435 | 446 |
436 if (using_ssl_) | 447 if (using_ssl_) |
437 connection_group = StringPrintf("ssl/%s", connection_group.c_str()); | 448 connection_group = StringPrintf("ssl/%s", connection_group.c_str()); |
438 | 449 |
439 // If the user is refreshing the page, bypass the host cache. | 450 // If the user is refreshing the page, bypass the host cache. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 if (ssl_started && (result == OK || IsCertificateError(result))) { | 573 if (ssl_started && (result == OK || IsCertificateError(result))) { |
563 SSLClientSocket* ssl_socket = | 574 SSLClientSocket* ssl_socket = |
564 static_cast<SSLClientSocket*>(connection_->socket()); | 575 static_cast<SSLClientSocket*>(connection_->socket()); |
565 if (ssl_socket->was_npn_negotiated()) { | 576 if (ssl_socket->was_npn_negotiated()) { |
566 was_npn_negotiated_ = true; | 577 was_npn_negotiated_ = true; |
567 if (ssl_socket->was_spdy_negotiated()) | 578 if (ssl_socket->was_spdy_negotiated()) |
568 using_spdy_ = true; | 579 using_spdy_ = true; |
569 } | 580 } |
570 if (force_spdy_over_ssl_ && force_spdy_always_) | 581 if (force_spdy_over_ssl_ && force_spdy_always_) |
571 using_spdy_ = true; | 582 using_spdy_ = true; |
| 583 } else if (proxy_info()->is_https() && connection_->socket() && |
| 584 result == OK) { |
| 585 HttpProxyClientSocket* proxy_socket = |
| 586 static_cast<HttpProxyClientSocket*>(connection_->socket()); |
| 587 if (proxy_socket->using_spdy()) { |
| 588 was_npn_negotiated_ = true; |
| 589 using_spdy_ = true; |
| 590 } |
572 } | 591 } |
573 | 592 |
574 // We may be using spdy without SSL | 593 // We may be using spdy without SSL |
575 if (!force_spdy_over_ssl_ && force_spdy_always_) | 594 if (!force_spdy_over_ssl_ && force_spdy_always_) |
576 using_spdy_ = true; | 595 using_spdy_ = true; |
577 | 596 |
578 if (result == ERR_PROXY_AUTH_REQUESTED) { | 597 if (result == ERR_PROXY_AUTH_REQUESTED) { |
579 DCHECK(!ssl_started); | 598 DCHECK(!ssl_started); |
580 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an | 599 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an |
581 // SSL socket, but there was an error before that could happen. This | 600 // SSL socket, but there was an error before that could happen. This |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 next_state_ = STATE_CREATE_STREAM_COMPLETE; | 666 next_state_ = STATE_CREATE_STREAM_COMPLETE; |
648 | 667 |
649 if (!using_spdy_) { | 668 if (!using_spdy_) { |
650 HttpBasicStream* stream = new HttpBasicStream(connection_.get()); | 669 HttpBasicStream* stream = new HttpBasicStream(connection_.get()); |
651 stream_.reset(new HttpStreamHandle(connection_.release(), stream)); | 670 stream_.reset(new HttpStreamHandle(connection_.release(), stream)); |
652 return OK; | 671 return OK; |
653 } | 672 } |
654 | 673 |
655 CHECK(!stream_.get()); | 674 CHECK(!stream_.get()); |
656 | 675 |
| 676 bool direct = true; |
657 const scoped_refptr<SpdySessionPool> spdy_pool = | 677 const scoped_refptr<SpdySessionPool> spdy_pool = |
658 session_->spdy_session_pool(); | 678 session_->spdy_session_pool(); |
659 scoped_refptr<SpdySession> spdy_session; | 679 scoped_refptr<SpdySession> spdy_session; |
660 | 680 |
661 HostPortProxyPair pair(endpoint_, proxy_info()->proxy_server()); | 681 const ProxyServer& proxy_server = proxy_info()->proxy_server(); |
662 if (session_->spdy_session_pool()->HasSession(pair)) { | 682 HostPortProxyPair pair(endpoint_, proxy_server); |
| 683 if (spdy_pool->HasSession(pair)) { |
| 684 // We have a SPDY session to the origin server. This might be a direct |
| 685 // connection, or it might be a SPDY session through an HTTP or HTTPS proxy. |
663 spdy_session = | 686 spdy_session = |
664 session_->spdy_session_pool()->Get(pair, session_, net_log_); | 687 spdy_pool->Get(pair, session_, net_log_); |
665 } else { | 688 } else if (proxy_info()->is_https()) { |
| 689 // If we don't have a direct SPDY session, and we're using an HTTPS |
| 690 // proxy, then we might have a SPDY session to the proxy |
| 691 pair = HostPortProxyPair(proxy_server.host_port_pair(), proxy_server); |
| 692 if (spdy_pool->HasSession(pair)) { |
| 693 spdy_session = spdy_pool->Get(pair, session_, net_log_); |
| 694 } |
| 695 direct = false; |
| 696 } |
| 697 |
| 698 if (!spdy_session.get()) { |
666 // SPDY can be negotiated using the TLS next protocol negotiation (NPN) | 699 // SPDY can be negotiated using the TLS next protocol negotiation (NPN) |
667 // extension, or just directly using SSL. Either way, |connection_| must | 700 // extension, or just directly using SSL. Either way, |connection_| must |
668 // contain an SSLClientSocket. | 701 // contain an SSLClientSocket. |
669 CHECK(connection_->socket()); | 702 CHECK(connection_->socket()); |
670 int error = spdy_pool->GetSpdySessionFromSocket( | 703 int error = spdy_pool->GetSpdySessionFromSocket( |
671 pair, session_, connection_.release(), net_log_, | 704 pair, session_, connection_.release(), net_log_, |
672 spdy_certificate_error_, &spdy_session, using_ssl_); | 705 spdy_certificate_error_, &spdy_session, using_ssl_); |
673 if (error != OK) | 706 if (error != OK) |
674 return error; | 707 return error; |
675 } | 708 } |
676 | 709 |
677 if (spdy_session->IsClosed()) | 710 if (spdy_session->IsClosed()) |
678 return ERR_CONNECTION_CLOSED; | 711 return ERR_CONNECTION_CLOSED; |
679 | 712 |
680 SpdyHttpStream* stream = new SpdyHttpStream(spdy_session); | 713 SpdyHttpStream* stream = new SpdyHttpStream(spdy_session, direct); |
681 stream_.reset(new HttpStreamHandle(NULL, stream)); | 714 stream_.reset(new HttpStreamHandle(NULL, stream)); |
682 return OK; | 715 return OK; |
683 } | 716 } |
684 | 717 |
685 int HttpStreamRequest::DoCreateStreamComplete(int result) { | 718 int HttpStreamRequest::DoCreateStreamComplete(int result) { |
686 if (result < 0) | 719 if (result < 0) |
687 return result; | 720 return result; |
688 | 721 |
689 next_state_ = STATE_NONE; | 722 next_state_ = STATE_NONE; |
690 return OK; | 723 return OK; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 base::TimeDelta::FromMinutes(6), | 956 base::TimeDelta::FromMinutes(6), |
924 100); | 957 100); |
925 break; | 958 break; |
926 default: | 959 default: |
927 NOTREACHED(); | 960 NOTREACHED(); |
928 break; | 961 break; |
929 } | 962 } |
930 } | 963 } |
931 | 964 |
932 } // namespace net | 965 } // namespace net |
OLD | NEW |