| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 const HttpAlternateProtocols::PortProtocolPair existing_alternate = | 187 const HttpAlternateProtocols::PortProtocolPair existing_alternate = |
| 188 alternate_protocols->GetAlternateProtocolFor(host_port); | 188 alternate_protocols->GetAlternateProtocolFor(host_port); |
| 189 // If we think the alternate protocol is broken, don't change it. | 189 // If we think the alternate protocol is broken, don't change it. |
| 190 if (existing_alternate.protocol == HttpAlternateProtocols::BROKEN) | 190 if (existing_alternate.protocol == HttpAlternateProtocols::BROKEN) |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 alternate_protocols->SetAlternateProtocolFor(host_port, port, protocol); | 194 alternate_protocols->SetAlternateProtocolFor(host_port, port, protocol); |
| 195 } | 195 } |
| 196 | 196 |
| 197 GURL UpgradeUrlToHttps(const GURL& original_url) { |
| 198 GURL::Replacements replacements; |
| 199 // new_sheme and new_port need to be in scope here because GURL::Replacements |
| 200 // references the memory contained by them directly. |
| 201 const std::string new_scheme = "https"; |
| 202 const std::string new_port = IntToString(443); |
| 203 replacements.SetSchemeStr(new_scheme); |
| 204 replacements.SetPortStr(new_port); |
| 205 return original_url.ReplaceComponents(replacements); |
| 206 } |
| 207 |
| 197 } // namespace | 208 } // namespace |
| 198 | 209 |
| 199 //----------------------------------------------------------------------------- | 210 //----------------------------------------------------------------------------- |
| 200 | 211 |
| 201 bool HttpNetworkTransaction::g_ignore_certificate_errors = false; | 212 bool HttpNetworkTransaction::g_ignore_certificate_errors = false; |
| 202 | 213 |
| 203 HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) | 214 HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) |
| 204 : pending_auth_target_(HttpAuth::AUTH_NONE), | 215 : pending_auth_target_(HttpAuth::AUTH_NONE), |
| 205 ALLOW_THIS_IN_INITIALIZER_LIST( | 216 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 206 io_callback_(this, &HttpNetworkTransaction::OnIOComplete)), | 217 io_callback_(this, &HttpNetworkTransaction::OnIOComplete)), |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 if (alternate_protocol_mode_ == kUnspecified) { | 686 if (alternate_protocol_mode_ == kUnspecified) { |
| 676 HttpAlternateProtocols::PortProtocolPair alternate = | 687 HttpAlternateProtocols::PortProtocolPair alternate = |
| 677 alternate_protocols.GetAlternateProtocolFor(endpoint_); | 688 alternate_protocols.GetAlternateProtocolFor(endpoint_); |
| 678 if (alternate.protocol != HttpAlternateProtocols::BROKEN) { | 689 if (alternate.protocol != HttpAlternateProtocols::BROKEN) { |
| 679 DCHECK_LE(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); | 690 DCHECK_LE(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); |
| 680 DCHECK_GT(HttpAlternateProtocols::NUM_ALTERNATE_PROTOCOLS, | 691 DCHECK_GT(HttpAlternateProtocols::NUM_ALTERNATE_PROTOCOLS, |
| 681 alternate.protocol); | 692 alternate.protocol); |
| 682 endpoint_.set_port(alternate.port); | 693 endpoint_.set_port(alternate.port); |
| 683 alternate_protocol_ = alternate.protocol; | 694 alternate_protocol_ = alternate.protocol; |
| 684 alternate_protocol_mode_ = kUsingAlternateProtocol; | 695 alternate_protocol_mode_ = kUsingAlternateProtocol; |
| 685 | 696 alternate_endpoint_url = UpgradeUrlToHttps(*curr_endpoint_url); |
| 686 url_canon::Replacements<char> replacements; | |
| 687 replacements.SetScheme("https", | |
| 688 url_parse::Component(0, strlen("https"))); | |
| 689 const std::string port_str = base::IntToString(endpoint_.port()); | |
| 690 replacements.SetPort(port_str.c_str(), | |
| 691 url_parse::Component(0, port_str.size())); | |
| 692 alternate_endpoint_url = | |
| 693 curr_endpoint_url->ReplaceComponents(replacements); | |
| 694 curr_endpoint_url = &alternate_endpoint_url; | 697 curr_endpoint_url = &alternate_endpoint_url; |
| 695 } | 698 } |
| 696 } | 699 } |
| 697 } | 700 } |
| 698 | 701 |
| 699 if (request_->load_flags & LOAD_BYPASS_PROXY) { | 702 if (request_->load_flags & LOAD_BYPASS_PROXY) { |
| 700 proxy_info_.UseDirect(); | 703 proxy_info_.UseDirect(); |
| 701 return OK; | 704 return OK; |
| 702 } | 705 } |
| 703 | 706 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 request_->referrer, | 775 request_->referrer, |
| 773 disable_resolver_cache); | 776 disable_resolver_cache); |
| 774 } else { | 777 } else { |
| 775 ProxyServer proxy_server = proxy_info_.proxy_server(); | 778 ProxyServer proxy_server = proxy_info_.proxy_server(); |
| 776 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); | 779 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); |
| 777 scoped_refptr<TCPSocketParams> proxy_tcp_params = | 780 scoped_refptr<TCPSocketParams> proxy_tcp_params = |
| 778 new TCPSocketParams(*proxy_host_port, request_->priority, | 781 new TCPSocketParams(*proxy_host_port, request_->priority, |
| 779 request_->referrer, disable_resolver_cache); | 782 request_->referrer, disable_resolver_cache); |
| 780 | 783 |
| 781 if (proxy_info_.is_http()) { | 784 if (proxy_info_.is_http()) { |
| 785 GURL authentication_url = request_->url; |
| 786 if (using_ssl_) { |
| 787 if (!authentication_url.SchemeIs("https")) { |
| 788 // If a proxy tunnel connection needs to be established due to |
| 789 // an Alternate-Protocol, the URL needs to be changed to indicate |
| 790 // https or digest authentication attempts will fail. |
| 791 // For example, suppose the initial request was for |
| 792 // "http://www.example.com/index.html". If this is an SSL |
| 793 // upgrade due to alternate protocol, the digest authorization |
| 794 // should have a uri="www.example.com:443" field rather than a |
| 795 // "/index.html" entry, even though the original request URL has not |
| 796 // changed. |
| 797 authentication_url = UpgradeUrlToHttps(authentication_url); |
| 798 } |
| 799 } |
| 782 establishing_tunnel_ = using_ssl_; | 800 establishing_tunnel_ = using_ssl_; |
| 783 http_proxy_params = new HttpProxySocketParams(proxy_tcp_params, | 801 http_proxy_params = new HttpProxySocketParams(proxy_tcp_params, |
| 784 request_->url, endpoint_, | 802 authentication_url, |
| 803 endpoint_, |
| 785 session_, using_ssl_); | 804 session_, using_ssl_); |
| 786 } else { | 805 } else { |
| 787 DCHECK(proxy_info_.is_socks()); | 806 DCHECK(proxy_info_.is_socks()); |
| 788 char socks_version; | 807 char socks_version; |
| 789 if (proxy_server.scheme() == ProxyServer::SCHEME_SOCKS5) | 808 if (proxy_server.scheme() == ProxyServer::SCHEME_SOCKS5) |
| 790 socks_version = '5'; | 809 socks_version = '5'; |
| 791 else | 810 else |
| 792 socks_version = '4'; | 811 socks_version = '4'; |
| 793 connection_group = | 812 connection_group = |
| 794 StringPrintf("socks%c/%s", socks_version, connection_group.c_str()); | 813 StringPrintf("socks%c/%s", socks_version, connection_group.c_str()); |
| (...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 default: | 1913 default: |
| 1895 return priority; | 1914 return priority; |
| 1896 } | 1915 } |
| 1897 } | 1916 } |
| 1898 | 1917 |
| 1899 | 1918 |
| 1900 | 1919 |
| 1901 #undef STATE_CASE | 1920 #undef STATE_CASE |
| 1902 | 1921 |
| 1903 } // namespace net | 1922 } // namespace net |
| OLD | NEW |