[email protected] | ac3fa8e2 | 2010-02-05 19:13:29 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
| 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 7 | #include "base/compiler_specific.h" |
[email protected] | 0b48db4 | 2009-03-23 02:45:11 | [diff] [blame] | 8 | #include "base/field_trial.h" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9 | #include "base/format_macros.h" |
[email protected] | 2198394 | 2009-08-18 06:17:50 | [diff] [blame] | 10 | #include "base/histogram.h" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11 | #include "base/scoped_ptr.h" |
[email protected] | 5e2e6c77d1 | 2009-12-24 21:57:16 | [diff] [blame] | 12 | #include "base/stats_counters.h" |
[email protected] | aeaca1f | 2010-04-20 22:05:21 | [diff] [blame] | 13 | #include "base/stl_util-inl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 15 | #include "base/trace_event.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | 5d0153c51 | 2009-01-12 19:08:36 | [diff] [blame] | 17 | #include "net/base/connection_type_histograms.h" |
[email protected] | 74a85ce | 2009-02-12 00:03:19 | [diff] [blame] | 18 | #include "net/base/io_buffer.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 19 | #include "net/base/load_flags.h" |
[email protected] | 597cf6e | 2009-05-29 09:43:26 | [diff] [blame] | 20 | #include "net/base/net_errors.h" |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 21 | #include "net/base/net_util.h" |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 22 | #include "net/base/ssl_cert_request_info.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 23 | #include "net/base/upload_data_stream.h" |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 24 | #include "net/http/http_auth.h" |
| 25 | #include "net/http/http_auth_handler.h" |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 26 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 27 | #include "net/http/http_chunked_decoder.h" |
| 28 | #include "net/http/http_network_session.h" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 29 | #include "net/http/http_request_headers.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 30 | #include "net/http/http_request_info.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 31 | #include "net/http/http_response_headers.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 32 | #include "net/http/http_response_info.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 33 | #include "net/http/http_util.h" |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 34 | #include "net/http/url_security_manager.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 35 | #include "net/socket/client_socket_factory.h" |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 36 | #include "net/socket/socks_client_socket_pool.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 37 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 7fc5b09a | 2010-02-27 00:07:38 | [diff] [blame] | 38 | #include "net/socket/tcp_client_socket_pool.h" |
[email protected] | dab9c7d | 2010-02-06 21:44:32 | [diff] [blame] | 39 | #include "net/spdy/spdy_session.h" |
| 40 | #include "net/spdy/spdy_session_pool.h" |
| 41 | #include "net/spdy/spdy_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 42 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 43 | using base::Time; |
| 44 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 45 | namespace net { |
| 46 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 47 | namespace { |
| 48 | |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 49 | const std::string* g_next_protos = NULL; |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 50 | bool g_use_alternate_protocols = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 51 | |
[email protected] | aeaca1f | 2010-04-20 22:05:21 | [diff] [blame] | 52 | // A set of host:port strings. These are servers which we have needed to back |
| 53 | // off to SSLv3 for. |
| 54 | std::set<std::string>* g_tls_intolerant_servers = NULL; |
| 55 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 56 | void BuildRequestHeaders(const HttpRequestInfo* request_info, |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 57 | const HttpRequestHeaders& authorization_headers, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 58 | const UploadDataStream* upload_data_stream, |
| 59 | bool using_proxy, |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 60 | std::string* request_line, |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 61 | HttpRequestHeaders* request_headers) { |
| 62 | const std::string path = using_proxy ? |
| 63 | HttpUtil::SpecForRequest(request_info->url) : |
| 64 | HttpUtil::PathForRequest(request_info->url); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 65 | *request_line = StringPrintf( |
| 66 | "%s %s HTTP/1.1\r\n", request_info->method.c_str(), path.c_str()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 67 | request_headers->SetHeader(HttpRequestHeaders::kHost, |
| 68 | GetHostAndOptionalPort(request_info->url)); |
| 69 | |
| 70 | // For compat with HTTP/1.0 servers and proxies: |
| 71 | if (using_proxy) { |
| 72 | request_headers->SetHeader(HttpRequestHeaders::kProxyConnection, |
| 73 | "keep-alive"); |
| 74 | } else { |
| 75 | request_headers->SetHeader(HttpRequestHeaders::kConnection, "keep-alive"); |
| 76 | } |
| 77 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 78 | // Our consumer should have made sure that this is a safe referrer. See for |
| 79 | // instance WebCore::FrameLoader::HideReferrer. |
| 80 | if (request_info->referrer.is_valid()) { |
| 81 | request_headers->SetHeader(HttpRequestHeaders::kReferer, |
| 82 | request_info->referrer.spec()); |
| 83 | } |
| 84 | |
| 85 | // Add a content length header? |
| 86 | if (upload_data_stream) { |
| 87 | request_headers->SetHeader( |
| 88 | HttpRequestHeaders::kContentLength, |
| 89 | Uint64ToString(upload_data_stream->size())); |
| 90 | } else if (request_info->method == "POST" || request_info->method == "PUT" || |
| 91 | request_info->method == "HEAD") { |
| 92 | // An empty POST/PUT request still needs a content length. As for HEAD, |
| 93 | // IE and Safari also add a content length header. Presumably it is to |
| 94 | // support sending a HEAD request to an URL that only expects to be sent a |
| 95 | // POST or some other method that normally would have a message body. |
| 96 | request_headers->SetHeader(HttpRequestHeaders::kContentLength, "0"); |
| 97 | } |
| 98 | |
| 99 | // Honor load flags that impact proxy caches. |
| 100 | if (request_info->load_flags & LOAD_BYPASS_CACHE) { |
| 101 | request_headers->SetHeader(HttpRequestHeaders::kPragma, "no-cache"); |
| 102 | request_headers->SetHeader(HttpRequestHeaders::kCacheControl, "no-cache"); |
| 103 | } else if (request_info->load_flags & LOAD_VALIDATE_CACHE) { |
| 104 | request_headers->SetHeader(HttpRequestHeaders::kCacheControl, "max-age=0"); |
| 105 | } |
| 106 | |
| 107 | request_headers->MergeFrom(authorization_headers); |
| 108 | |
[email protected] | 860c85d | 2010-02-10 07:22:40 | [diff] [blame] | 109 | // Headers that will be stripped from request_info->extra_headers to prevent, |
| 110 | // e.g., plugins from overriding headers that are controlled using other |
| 111 | // means. Otherwise a plugin could set a referrer although sending the |
| 112 | // referrer is inhibited. |
| 113 | // TODO(jochen): check whether also other headers should be stripped. |
| 114 | static const char* const kExtraHeadersToBeStripped[] = { |
| 115 | "Referer" |
| 116 | }; |
| 117 | |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 118 | HttpRequestHeaders stripped_extra_headers; |
| 119 | stripped_extra_headers.CopyFrom(request_info->extra_headers); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 120 | for (size_t i = 0; i < arraysize(kExtraHeadersToBeStripped); ++i) |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 121 | stripped_extra_headers.RemoveHeader(kExtraHeadersToBeStripped[i]); |
| 122 | request_headers->MergeFrom(stripped_extra_headers); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | // The HTTP CONNECT method for establishing a tunnel connection is documented |
| 126 | // in draft-luotonen-web-proxy-tunneling-01.txt and RFC 2817, Sections 5.2 and |
| 127 | // 5.3. |
| 128 | void BuildTunnelRequest(const HttpRequestInfo* request_info, |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 129 | const HttpRequestHeaders& authorization_headers, |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 130 | std::string* request_line, |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 131 | HttpRequestHeaders* request_headers) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 132 | // RFC 2616 Section 9 says the Host request-header field MUST accompany all |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 133 | // HTTP/1.1 requests. Add "Proxy-Connection: keep-alive" for compat with |
| 134 | // HTTP/1.0 proxies such as Squid (required for NTLM authentication). |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 135 | *request_line = StringPrintf( |
| 136 | "CONNECT %s HTTP/1.1\r\n", GetHostAndPort(request_info->url).c_str()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 137 | request_headers->SetHeader(HttpRequestHeaders::kHost, |
| 138 | GetHostAndOptionalPort(request_info->url)); |
| 139 | request_headers->SetHeader(HttpRequestHeaders::kProxyConnection, |
| 140 | "keep-alive"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 141 | |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 142 | std::string user_agent; |
| 143 | if (request_info->extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, |
| 144 | &user_agent)) |
| 145 | request_headers->SetHeader(HttpRequestHeaders::kUserAgent, user_agent); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 146 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 147 | request_headers->MergeFrom(authorization_headers); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 150 | void ProcessAlternateProtocol(const HttpResponseHeaders& headers, |
| 151 | const HostPortPair& http_host_port_pair, |
| 152 | HttpAlternateProtocols* alternate_protocols) { |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 153 | if (!g_next_protos || g_next_protos->empty()) { |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 154 | // This implies that NPN is not supported. We don't currently support any |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 155 | // alternate protocols that don't use NPN. |
| 156 | return; |
| 157 | } |
| 158 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 159 | std::string alternate_protocol_str; |
| 160 | if (!headers.EnumerateHeader(NULL, HttpAlternateProtocols::kHeader, |
| 161 | &alternate_protocol_str)) { |
| 162 | // Header is not present. |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | std::vector<std::string> port_protocol_vector; |
| 167 | SplitString(alternate_protocol_str, ':', &port_protocol_vector); |
| 168 | if (port_protocol_vector.size() != 2) { |
| 169 | DLOG(WARNING) << HttpAlternateProtocols::kHeader |
| 170 | << " header has too many tokens: " |
| 171 | << alternate_protocol_str; |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | int port; |
| 176 | if (!StringToInt(port_protocol_vector[0], &port) || |
| 177 | port <= 0 || port >= 1 << 16) { |
| 178 | DLOG(WARNING) << HttpAlternateProtocols::kHeader |
| 179 | << " header has unrecognizable port: " |
| 180 | << port_protocol_vector[0]; |
| 181 | return; |
| 182 | } |
| 183 | |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 184 | if (port_protocol_vector[1] != |
| 185 | HttpAlternateProtocols::kProtocolStrings[ |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 186 | HttpAlternateProtocols::NPN_SPDY_1]) { |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 187 | // Currently, we only recognize the npn-spdy protocol. |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 188 | DLOG(WARNING) << HttpAlternateProtocols::kHeader |
| 189 | << " header has unrecognized protocol: " |
| 190 | << port_protocol_vector[1]; |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | if (alternate_protocols->HasAlternateProtocolFor(http_host_port_pair)) { |
| 195 | const HttpAlternateProtocols::PortProtocolPair existing_alternate = |
| 196 | alternate_protocols->GetAlternateProtocolFor(http_host_port_pair); |
| 197 | // If we think the alternate protocol is broken, don't change it. |
| 198 | if (existing_alternate.protocol == HttpAlternateProtocols::BROKEN) |
| 199 | return; |
| 200 | } |
| 201 | |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 202 | alternate_protocols->SetAlternateProtocolFor( |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 203 | http_host_port_pair, port, HttpAlternateProtocols::NPN_SPDY_1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 204 | } |
| 205 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 206 | } // namespace |
| 207 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 208 | //----------------------------------------------------------------------------- |
| 209 | |
[email protected] | 3ce7df0f | 2010-03-03 00:30:50 | [diff] [blame] | 210 | bool HttpNetworkTransaction::g_ignore_certificate_errors = false; |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 211 | |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 212 | HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 213 | : pending_auth_target_(HttpAuth::AUTH_NONE), |
| 214 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 215 | io_callback_(this, &HttpNetworkTransaction::OnIOComplete)), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 216 | user_callback_(NULL), |
| 217 | session_(session), |
| 218 | request_(NULL), |
| 219 | pac_request_(NULL), |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 220 | connection_(new ClientSocketHandle), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 221 | reused_socket_(false), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 222 | headers_valid_(false), |
| 223 | logged_response_time(false), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 224 | using_ssl_(false), |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 225 | proxy_mode_(kDirectConnection), |
[email protected] | 6b9833e | 2008-09-10 20:32:25 | [diff] [blame] | 226 | establishing_tunnel_(false), |
[email protected] | e099391 | 2010-02-22 23:57:11 | [diff] [blame] | 227 | using_spdy_(false), |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 228 | alternate_protocol_mode_( |
| 229 | g_use_alternate_protocols ? kUnspecified : |
| 230 | kDoNotUseAlternateProtocol), |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 231 | embedded_identity_used_(false), |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 232 | default_credentials_used_(false), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 233 | read_buf_len_(0), |
| 234 | next_state_(STATE_NONE) { |
[email protected] | 2cd713f | 2008-10-21 17:54:28 | [diff] [blame] | 235 | session->ssl_config_service()->GetSSLConfig(&ssl_config_); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 236 | if (g_next_protos) |
| 237 | ssl_config_.next_protos = *g_next_protos; |
[email protected] | aeaca1f | 2010-04-20 22:05:21 | [diff] [blame] | 238 | if (!g_tls_intolerant_servers) |
| 239 | g_tls_intolerant_servers = new std::set<std::string>; |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // static |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 243 | void HttpNetworkTransaction::SetUseAlternateProtocols(bool value) { |
| 244 | g_use_alternate_protocols = value; |
| 245 | } |
| 246 | |
| 247 | // static |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 248 | void HttpNetworkTransaction::SetNextProtos(const std::string& next_protos) { |
| 249 | delete g_next_protos; |
| 250 | g_next_protos = new std::string(next_protos); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | 3ce7df0f | 2010-03-03 00:30:50 | [diff] [blame] | 253 | // static |
| 254 | void HttpNetworkTransaction::IgnoreCertificateErrors(bool enabled) { |
| 255 | g_ignore_certificate_errors = enabled; |
| 256 | } |
| 257 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 258 | int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, |
| 259 | CompletionCallback* callback, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 260 | const BoundNetLog& net_log) { |
[email protected] | 5e2e6c77d1 | 2009-12-24 21:57:16 | [diff] [blame] | 261 | SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count"); |
[email protected] | 5d0153c51 | 2009-01-12 19:08:36 | [diff] [blame] | 262 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 263 | net_log_ = net_log; |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 264 | request_ = request_info; |
[email protected] | 21b316a | 2009-03-23 18:25:06 | [diff] [blame] | 265 | start_time_ = base::Time::Now(); |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 266 | |
| 267 | next_state_ = STATE_RESOLVE_PROXY; |
| 268 | int rv = DoLoop(OK); |
| 269 | if (rv == ERR_IO_PENDING) |
| 270 | user_callback_ = callback; |
| 271 | return rv; |
| 272 | } |
| 273 | |
| 274 | int HttpNetworkTransaction::RestartIgnoringLastError( |
| 275 | CompletionCallback* callback) { |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 276 | if (connection_->socket()->IsConnectedAndIdle()) { |
[email protected] | fab9ca5 | 2010-02-19 23:14:48 | [diff] [blame] | 277 | // TODO(wtc): Should we update any of the connection histograms that we |
| 278 | // update in DoSSLConnectComplete if |result| is OK? |
[email protected] | e099391 | 2010-02-22 23:57:11 | [diff] [blame] | 279 | if (using_spdy_) { |
[email protected] | fab9ca5 | 2010-02-19 23:14:48 | [diff] [blame] | 280 | next_state_ = STATE_SPDY_SEND_REQUEST; |
| 281 | } else { |
| 282 | next_state_ = STATE_SEND_REQUEST; |
| 283 | } |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 284 | } else { |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 285 | connection_->socket()->Disconnect(); |
| 286 | connection_->Reset(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 287 | next_state_ = STATE_INIT_CONNECTION; |
| 288 | } |
[email protected] | ccb40e5 | 2008-09-17 20:54:40 | [diff] [blame] | 289 | int rv = DoLoop(OK); |
| 290 | if (rv == ERR_IO_PENDING) |
| 291 | user_callback_ = callback; |
[email protected] | aaead50 | 2008-10-15 00:20:11 | [diff] [blame] | 292 | return rv; |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 295 | int HttpNetworkTransaction::RestartWithCertificate( |
| 296 | X509Certificate* client_cert, |
| 297 | CompletionCallback* callback) { |
| 298 | ssl_config_.client_cert = client_cert; |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 299 | if (client_cert) { |
| 300 | session_->ssl_client_auth_cache()->Add(GetHostAndPort(request_->url), |
| 301 | client_cert); |
| 302 | } |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 303 | ssl_config_.send_client_cert = true; |
| 304 | next_state_ = STATE_INIT_CONNECTION; |
| 305 | // Reset the other member variables. |
| 306 | // Note: this is necessary only with SSL renegotiation. |
| 307 | ResetStateForRestart(); |
| 308 | int rv = DoLoop(OK); |
| 309 | if (rv == ERR_IO_PENDING) |
| 310 | user_callback_ = callback; |
| 311 | return rv; |
| 312 | } |
| 313 | |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 314 | int HttpNetworkTransaction::RestartWithAuth( |
| 315 | const std::wstring& username, |
| 316 | const std::wstring& password, |
| 317 | CompletionCallback* callback) { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 318 | HttpAuth::Target target = pending_auth_target_; |
| 319 | if (target == HttpAuth::AUTH_NONE) { |
| 320 | NOTREACHED(); |
| 321 | return ERR_UNEXPECTED; |
| 322 | } |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 323 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 324 | pending_auth_target_ = HttpAuth::AUTH_NONE; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 325 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 326 | DCHECK(auth_identity_[target].invalid || |
| 327 | (username.empty() && password.empty())); |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 328 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 329 | if (auth_identity_[target].invalid) { |
| 330 | // Update the username/password. |
| 331 | auth_identity_[target].source = HttpAuth::IDENT_SRC_EXTERNAL; |
| 332 | auth_identity_[target].invalid = false; |
| 333 | auth_identity_[target].username = username; |
| 334 | auth_identity_[target].password = password; |
| 335 | } |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 336 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 337 | PrepareForAuthRestart(target); |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 338 | |
| 339 | DCHECK(user_callback_ == NULL); |
| 340 | int rv = DoLoop(OK); |
| 341 | if (rv == ERR_IO_PENDING) |
| 342 | user_callback_ = callback; |
| 343 | |
| 344 | return rv; |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 345 | } |
| 346 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 347 | void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) { |
| 348 | DCHECK(HaveAuth(target)); |
| 349 | DCHECK(auth_identity_[target].source != HttpAuth::IDENT_SRC_PATH_LOOKUP); |
| 350 | |
| 351 | // Add the auth entry to the cache before restarting. We don't know whether |
| 352 | // the identity is valid yet, but if it is valid we want other transactions |
| 353 | // to know about it. If an entry for (origin, handler->realm()) already |
| 354 | // exists, we update it. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 355 | // |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 356 | // If auth_identity_[target].source is HttpAuth::IDENT_SRC_NONE or |
| 357 | // HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS, auth_identity_[target] contains |
| 358 | // no identity because identity is not required yet or we're using default |
| 359 | // credentials. |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 360 | // |
| 361 | // TODO(wtc): For NTLM_SSPI, we add the same auth entry to the cache in |
| 362 | // round 1 and round 2, which is redundant but correct. It would be nice |
| 363 | // to add an auth entry to the cache only once, preferrably in round 1. |
| 364 | // See http://crbug.com/21015. |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 365 | switch (auth_identity_[target].source) { |
| 366 | case HttpAuth::IDENT_SRC_NONE: |
| 367 | case HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS: |
| 368 | break; |
| 369 | default: |
| 370 | session_->auth_cache()->Add( |
| 371 | AuthOrigin(target), auth_handler_[target], |
| 372 | auth_identity_[target].username, auth_identity_[target].password, |
| 373 | AuthPath(target)); |
| 374 | break; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 375 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 376 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 377 | bool keep_alive = false; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 378 | // Even if the server says the connection is keep-alive, we have to be |
| 379 | // able to find the end of each response in order to reuse the connection. |
| 380 | if (GetResponseHeaders()->IsKeepAlive() && |
| 381 | http_stream_->CanFindEndOfResponse()) { |
| 382 | // If the response body hasn't been completely read, we need to drain |
| 383 | // it first. |
| 384 | if (!http_stream_->IsResponseBodyComplete()) { |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 385 | next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 386 | read_buf_ = new IOBuffer(kDrainBodyBufferSize); // A bit bucket. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 387 | read_buf_len_ = kDrainBodyBufferSize; |
| 388 | return; |
| 389 | } |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 390 | keep_alive = true; |
[email protected] | 37832c6d | 2009-06-05 19:44:09 | [diff] [blame] | 391 | } |
| 392 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 393 | // We don't need to drain the response body, so we act as if we had drained |
| 394 | // the response body. |
| 395 | DidDrainBodyForAuthRestart(keep_alive); |
| 396 | } |
| 397 | |
| 398 | void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 399 | if (keep_alive && connection_->socket()->IsConnectedAndIdle()) { |
| 400 | // We should call connection_->set_idle_time(), but this doesn't occur |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 401 | // often enough to be worth the trouble. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 402 | next_state_ = STATE_SEND_REQUEST; |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 403 | connection_->set_is_reused(true); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 404 | reused_socket_ = true; |
| 405 | } else { |
| 406 | next_state_ = STATE_INIT_CONNECTION; |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 407 | connection_->socket()->Disconnect(); |
| 408 | connection_->Reset(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 409 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 410 | |
| 411 | // Reset the other member variables. |
| 412 | ResetStateForRestart(); |
| 413 | } |
| 414 | |
[email protected] | 9dea9e1f | 2009-01-29 00:30:47 | [diff] [blame] | 415 | int HttpNetworkTransaction::Read(IOBuffer* buf, int buf_len, |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 416 | CompletionCallback* callback) { |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 417 | DCHECK(buf); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 418 | DCHECK_LT(0, buf_len); |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 419 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 420 | State next_state = STATE_NONE; |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 421 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 422 | // Are we using SPDY or HTTP? |
[email protected] | e099391 | 2010-02-22 23:57:11 | [diff] [blame] | 423 | if (using_spdy_) { |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 424 | DCHECK(!http_stream_.get()); |
| 425 | DCHECK(spdy_stream_->GetResponseInfo()->headers); |
| 426 | next_state = STATE_SPDY_READ_BODY; |
| 427 | } else { |
[email protected] | e099391 | 2010-02-22 23:57:11 | [diff] [blame] | 428 | DCHECK(!spdy_stream_.get()); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 429 | scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
| 430 | DCHECK(headers.get()); |
| 431 | next_state = STATE_READ_BODY; |
| 432 | |
| 433 | if (!connection_->is_initialized()) |
| 434 | return 0; // connection_->has been reset. Treat like EOF. |
| 435 | |
| 436 | if (establishing_tunnel_) { |
| 437 | // We're trying to read the body of the response but we're still trying |
| 438 | // to establish an SSL tunnel through the proxy. We can't read these |
| 439 | // bytes when establishing a tunnel because they might be controlled by |
| 440 | // an active network attacker. We don't worry about this for HTTP |
| 441 | // because an active network attacker can already control HTTP sessions. |
| 442 | // We reach this case when the user cancels a 407 proxy auth prompt. |
| 443 | // See http://crbug.com/8473. |
| 444 | DCHECK_EQ(407, headers->response_code()); |
| 445 | LogBlockedTunnelResponse(headers->response_code()); |
| 446 | return ERR_TUNNEL_CONNECTION_FAILED; |
| 447 | } |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 450 | read_buf_ = buf; |
| 451 | read_buf_len_ = buf_len; |
| 452 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 453 | next_state_ = next_state; |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 454 | int rv = DoLoop(OK); |
| 455 | if (rv == ERR_IO_PENDING) |
| 456 | user_callback_ = callback; |
| 457 | return rv; |
| 458 | } |
| 459 | |
| 460 | const HttpResponseInfo* HttpNetworkTransaction::GetResponseInfo() const { |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 461 | return ((headers_valid_ && response_.headers) || response_.ssl_info.cert || |
| 462 | response_.cert_request_info) ? &response_ : NULL; |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | LoadState HttpNetworkTransaction::GetLoadState() const { |
| 466 | // TODO(wtc): Define a new LoadState value for the |
| 467 | // STATE_INIT_CONNECTION_COMPLETE state, which delays the HTTP request. |
| 468 | switch (next_state_) { |
| 469 | case STATE_RESOLVE_PROXY_COMPLETE: |
| 470 | return LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 471 | case STATE_INIT_CONNECTION_COMPLETE: |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 472 | return connection_->GetLoadState(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 473 | case STATE_SEND_REQUEST_COMPLETE: |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 474 | return LOAD_STATE_SENDING_REQUEST; |
| 475 | case STATE_READ_HEADERS_COMPLETE: |
| 476 | return LOAD_STATE_WAITING_FOR_RESPONSE; |
| 477 | case STATE_READ_BODY_COMPLETE: |
| 478 | return LOAD_STATE_READING_RESPONSE; |
| 479 | default: |
| 480 | return LOAD_STATE_IDLE; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | uint64 HttpNetworkTransaction::GetUploadProgress() const { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 485 | if (!http_stream_.get()) |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 486 | return 0; |
| 487 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 488 | return http_stream_->GetUploadProgress(); |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 489 | } |
| 490 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 491 | HttpNetworkTransaction::~HttpNetworkTransaction() { |
[email protected] | 92d9cad | 2009-06-25 23:40:24 | [diff] [blame] | 492 | // If we still have an open socket, then make sure to disconnect it so it |
| 493 | // won't call us back and we don't try to reuse it later on. |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 494 | if (connection_.get() && connection_->is_initialized()) |
| 495 | connection_->socket()->Disconnect(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 496 | |
| 497 | if (pac_request_) |
| 498 | session_->proxy_service()->CancelPacRequest(pac_request_); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 499 | |
| 500 | if (spdy_stream_.get()) |
| 501 | spdy_stream_->Cancel(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 502 | } |
| 503 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 504 | void HttpNetworkTransaction::DoCallback(int rv) { |
| 505 | DCHECK(rv != ERR_IO_PENDING); |
| 506 | DCHECK(user_callback_); |
| 507 | |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 508 | // Since Run may result in Read being called, clear user_callback_ up front. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 509 | CompletionCallback* c = user_callback_; |
| 510 | user_callback_ = NULL; |
| 511 | c->Run(rv); |
| 512 | } |
| 513 | |
| 514 | void HttpNetworkTransaction::OnIOComplete(int result) { |
| 515 | int rv = DoLoop(result); |
| 516 | if (rv != ERR_IO_PENDING) |
| 517 | DoCallback(rv); |
| 518 | } |
| 519 | |
| 520 | int HttpNetworkTransaction::DoLoop(int result) { |
| 521 | DCHECK(next_state_ != STATE_NONE); |
| 522 | |
| 523 | int rv = result; |
| 524 | do { |
| 525 | State state = next_state_; |
| 526 | next_state_ = STATE_NONE; |
| 527 | switch (state) { |
| 528 | case STATE_RESOLVE_PROXY: |
[email protected] | 725355a | 2009-03-25 20:42:55 | [diff] [blame] | 529 | DCHECK_EQ(OK, rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 530 | TRACE_EVENT_BEGIN("http.resolve_proxy", request_, request_->url.spec()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 531 | rv = DoResolveProxy(); |
| 532 | break; |
| 533 | case STATE_RESOLVE_PROXY_COMPLETE: |
| 534 | rv = DoResolveProxyComplete(rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 535 | TRACE_EVENT_END("http.resolve_proxy", request_, request_->url.spec()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 536 | break; |
| 537 | case STATE_INIT_CONNECTION: |
[email protected] | 725355a | 2009-03-25 20:42:55 | [diff] [blame] | 538 | DCHECK_EQ(OK, rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 539 | TRACE_EVENT_BEGIN("http.init_conn", request_, request_->url.spec()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 540 | rv = DoInitConnection(); |
| 541 | break; |
| 542 | case STATE_INIT_CONNECTION_COMPLETE: |
| 543 | rv = DoInitConnectionComplete(rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 544 | TRACE_EVENT_END("http.init_conn", request_, request_->url.spec()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 545 | break; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 546 | case STATE_SSL_CONNECT: |
[email protected] | 725355a | 2009-03-25 20:42:55 | [diff] [blame] | 547 | DCHECK_EQ(OK, rv); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 548 | TRACE_EVENT_BEGIN("http.ssl_connect", request_, request_->url.spec()); |
| 549 | rv = DoSSLConnect(); |
[email protected] | c7af8b2 | 2008-08-25 20:41:46 | [diff] [blame] | 550 | break; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 551 | case STATE_SSL_CONNECT_COMPLETE: |
| 552 | rv = DoSSLConnectComplete(rv); |
| 553 | TRACE_EVENT_END("http.ssl_connect", request_, request_->url.spec()); |
[email protected] | c7af8b2 | 2008-08-25 20:41:46 | [diff] [blame] | 554 | break; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 555 | case STATE_SEND_REQUEST: |
[email protected] | 725355a | 2009-03-25 20:42:55 | [diff] [blame] | 556 | DCHECK_EQ(OK, rv); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 557 | TRACE_EVENT_BEGIN("http.send_request", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 558 | net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 559 | rv = DoSendRequest(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 560 | break; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 561 | case STATE_SEND_REQUEST_COMPLETE: |
| 562 | rv = DoSendRequestComplete(rv); |
| 563 | TRACE_EVENT_END("http.send_request", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 564 | net_log_.EndEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 565 | break; |
| 566 | case STATE_READ_HEADERS: |
[email protected] | 725355a | 2009-03-25 20:42:55 | [diff] [blame] | 567 | DCHECK_EQ(OK, rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 568 | TRACE_EVENT_BEGIN("http.read_headers", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 569 | net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 570 | rv = DoReadHeaders(); |
| 571 | break; |
| 572 | case STATE_READ_HEADERS_COMPLETE: |
| 573 | rv = DoReadHeadersComplete(rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 574 | TRACE_EVENT_END("http.read_headers", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 575 | net_log_.EndEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 576 | break; |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 577 | case STATE_RESOLVE_CANONICAL_NAME: |
[email protected] | bd78665 | 2010-04-19 15:17:36 | [diff] [blame] | 578 | DCHECK_EQ(OK, rv); |
| 579 | net_log_.BeginEvent( |
| 580 | NetLog::TYPE_HTTP_TRANSACTION_RESOLVE_CANONICAL_NAME); |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 581 | rv = DoResolveCanonicalName(); |
| 582 | break; |
| 583 | case STATE_RESOLVE_CANONICAL_NAME_COMPLETE: |
| 584 | rv = DoResolveCanonicalNameComplete(rv); |
[email protected] | bd78665 | 2010-04-19 15:17:36 | [diff] [blame] | 585 | net_log_.EndEvent(NetLog::TYPE_HTTP_TRANSACTION_RESOLVE_CANONICAL_NAME); |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 586 | break; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 587 | case STATE_READ_BODY: |
[email protected] | 725355a | 2009-03-25 20:42:55 | [diff] [blame] | 588 | DCHECK_EQ(OK, rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 589 | TRACE_EVENT_BEGIN("http.read_body", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 590 | net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_BODY); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 591 | rv = DoReadBody(); |
| 592 | break; |
| 593 | case STATE_READ_BODY_COMPLETE: |
| 594 | rv = DoReadBodyComplete(rv); |
[email protected] | 113ab13 | 2008-09-18 20:42:55 | [diff] [blame] | 595 | TRACE_EVENT_END("http.read_body", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 596 | net_log_.EndEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_BODY); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 597 | break; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 598 | case STATE_DRAIN_BODY_FOR_AUTH_RESTART: |
[email protected] | 725355a | 2009-03-25 20:42:55 | [diff] [blame] | 599 | DCHECK_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 600 | TRACE_EVENT_BEGIN("http.drain_body_for_auth_restart", |
| 601 | request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 602 | net_log_.BeginEvent( |
| 603 | NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 604 | rv = DoDrainBodyForAuthRestart(); |
| 605 | break; |
| 606 | case STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE: |
| 607 | rv = DoDrainBodyForAuthRestartComplete(rv); |
| 608 | TRACE_EVENT_END("http.drain_body_for_auth_restart", |
| 609 | request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 610 | net_log_.EndEvent( |
| 611 | NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 612 | break; |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 613 | case STATE_SPDY_SEND_REQUEST: |
| 614 | DCHECK_EQ(OK, rv); |
| 615 | TRACE_EVENT_BEGIN("http.send_request", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 616 | net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 617 | rv = DoSpdySendRequest(); |
| 618 | break; |
| 619 | case STATE_SPDY_SEND_REQUEST_COMPLETE: |
| 620 | rv = DoSpdySendRequestComplete(rv); |
| 621 | TRACE_EVENT_END("http.send_request", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 622 | net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 623 | break; |
| 624 | case STATE_SPDY_READ_HEADERS: |
| 625 | DCHECK_EQ(OK, rv); |
| 626 | TRACE_EVENT_BEGIN("http.read_headers", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 627 | net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 628 | rv = DoSpdyReadHeaders(); |
| 629 | break; |
| 630 | case STATE_SPDY_READ_HEADERS_COMPLETE: |
| 631 | rv = DoSpdyReadHeadersComplete(rv); |
| 632 | TRACE_EVENT_END("http.read_headers", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 633 | net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 634 | break; |
| 635 | case STATE_SPDY_READ_BODY: |
| 636 | DCHECK_EQ(OK, rv); |
| 637 | TRACE_EVENT_BEGIN("http.read_body", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 638 | net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_BODY); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 639 | rv = DoSpdyReadBody(); |
| 640 | break; |
| 641 | case STATE_SPDY_READ_BODY_COMPLETE: |
| 642 | rv = DoSpdyReadBodyComplete(rv); |
| 643 | TRACE_EVENT_END("http.read_body", request_, request_->url.spec()); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 644 | net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_BODY); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 645 | break; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 646 | default: |
| 647 | NOTREACHED() << "bad state"; |
| 648 | rv = ERR_FAILED; |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 649 | break; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 650 | } |
| 651 | } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 652 | |
| 653 | return rv; |
| 654 | } |
| 655 | |
| 656 | int HttpNetworkTransaction::DoResolveProxy() { |
| 657 | DCHECK(!pac_request_); |
| 658 | |
| 659 | next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
| 660 | |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 661 | if (request_->load_flags & LOAD_BYPASS_PROXY) { |
| 662 | proxy_info_.UseDirect(); |
| 663 | return OK; |
| 664 | } |
| 665 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 666 | return session_->proxy_service()->ResolveProxy( |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 667 | request_->url, &proxy_info_, &io_callback_, &pac_request_, net_log_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | int HttpNetworkTransaction::DoResolveProxyComplete(int result) { |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 671 | pac_request_ = NULL; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 672 | |
[email protected] | dded3e2 | 2010-02-05 04:08:37 | [diff] [blame] | 673 | if (result != OK) |
| 674 | return result; |
[email protected] | 59a1601 | 2010-01-29 23:45:29 | [diff] [blame] | 675 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 676 | // Remove unsupported proxies from the list. |
[email protected] | f6fb2de | 2009-02-19 08:11:42 | [diff] [blame] | 677 | proxy_info_.RemoveProxiesWithoutScheme( |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 678 | ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 679 | ProxyServer::SCHEME_SOCKS4 | ProxyServer::SCHEME_SOCKS5); |
[email protected] | f6fb2de | 2009-02-19 08:11:42 | [diff] [blame] | 680 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 681 | if (proxy_info_.is_empty()) { |
[email protected] | 02cf5a4 | 2010-01-12 22:10:25 | [diff] [blame] | 682 | // No proxies/direct to choose from. This happens when we don't support any |
| 683 | // of the proxies in the returned list. |
| 684 | return ERR_NO_SUPPORTED_PROXIES; |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 685 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 686 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 687 | next_state_ = STATE_INIT_CONNECTION; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 688 | return OK; |
| 689 | } |
| 690 | |
| 691 | int HttpNetworkTransaction::DoInitConnection() { |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 692 | DCHECK(!connection_->is_initialized()); |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 693 | DCHECK(proxy_info_.proxy_server().is_valid()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 694 | |
| 695 | next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 696 | |
| 697 | using_ssl_ = request_->url.SchemeIs("https"); |
[email protected] | e099391 | 2010-02-22 23:57:11 | [diff] [blame] | 698 | using_spdy_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 699 | |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 700 | // TODO(vandebo) get rid of proxy_mode_, it's redundant |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 701 | if (proxy_info_.is_direct()) |
| 702 | proxy_mode_ = kDirectConnection; |
| 703 | else if (proxy_info_.proxy_server().is_socks()) |
| 704 | proxy_mode_ = kSOCKSProxy; |
| 705 | else if (using_ssl_) |
| 706 | proxy_mode_ = kHTTPProxyUsingTunnel; |
| 707 | else |
| 708 | proxy_mode_ = kHTTPProxy; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 709 | |
| 710 | // Build the string used to uniquely identify connections of this type. |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 711 | // Determine the host and port to connect to. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 712 | std::string connection_group; |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 713 | std::string host; |
| 714 | int port; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 715 | if (proxy_mode_ != kDirectConnection) { |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 716 | ProxyServer proxy_server = proxy_info_.proxy_server(); |
| 717 | connection_group = "proxy/" + proxy_server.ToURI() + "/"; |
| 718 | host = proxy_server.HostNoBrackets(); |
| 719 | port = proxy_server.port(); |
| 720 | } else { |
| 721 | host = request_->url.HostNoBrackets(); |
| 722 | port = request_->url.EffectiveIntPort(); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 723 | if (alternate_protocol_mode_ == kUnspecified) { |
| 724 | const HttpAlternateProtocols& alternate_protocols = |
| 725 | session_->alternate_protocols(); |
| 726 | if (alternate_protocols.HasAlternateProtocolFor(host, port)) { |
| 727 | HttpAlternateProtocols::PortProtocolPair alternate = |
| 728 | alternate_protocols.GetAlternateProtocolFor(host, port); |
| 729 | if (alternate.protocol != HttpAlternateProtocols::BROKEN) { |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 730 | DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 731 | port = alternate.port; |
| 732 | using_ssl_ = true; |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 733 | alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY_1; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 734 | alternate_protocol_mode_ = kUsingAlternateProtocol; |
| 735 | } |
| 736 | } |
| 737 | } |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 738 | } |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 739 | |
[email protected] | 85c0ed8 | 2009-12-15 23:14:14 | [diff] [blame] | 740 | // Use the fixed testing ports if they've been provided. |
| 741 | if (using_ssl_) { |
| 742 | if (session_->fixed_https_port() != 0) |
| 743 | port = session_->fixed_https_port(); |
| 744 | } else if (session_->fixed_http_port() != 0) { |
| 745 | port = session_->fixed_http_port(); |
| 746 | } |
| 747 | |
[email protected] | 7fc5b09a | 2010-02-27 00:07:38 | [diff] [blame] | 748 | // Check first if we have a spdy session for this group. If so, then go |
| 749 | // straight to using that. |
| 750 | HostPortPair host_port_pair(host, port); |
| 751 | if (session_->spdy_session_pool()->HasSession(host_port_pair)) { |
| 752 | using_spdy_ = true; |
| 753 | return OK; |
| 754 | } |
| 755 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 756 | // For a connection via HTTP proxy not using CONNECT, the connection |
| 757 | // is to the proxy server only. For all other cases |
| 758 | // (direct, HTTP proxy CONNECT, SOCKS), the connection is upto the |
| 759 | // url endpoint. Hence we append the url data into the connection_group. |
| 760 | if (proxy_mode_ != kHTTPProxy) |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 761 | connection_group.append(request_->url.GetOrigin().spec()); |
| 762 | |
[email protected] | a0ef376 | 2009-12-22 02:09:45 | [diff] [blame] | 763 | DCHECK(!connection_group.empty()); |
[email protected] | 2884a46 | 2009-06-15 05:08:42 | [diff] [blame] | 764 | |
[email protected] | 2884a46 | 2009-06-15 05:08:42 | [diff] [blame] | 765 | // If the user is refreshing the page, bypass the host cache. |
[email protected] | 7fc5b09a | 2010-02-27 00:07:38 | [diff] [blame] | 766 | bool disable_resolver_cache = request_->load_flags & LOAD_BYPASS_CACHE || |
| 767 | request_->load_flags & LOAD_DISABLE_CACHE; |
[email protected] | 2884a46 | 2009-06-15 05:08:42 | [diff] [blame] | 768 | |
[email protected] | 7fc5b09a | 2010-02-27 00:07:38 | [diff] [blame] | 769 | TCPSocketParams tcp_params(host, port, request_->priority, request_->referrer, |
| 770 | disable_resolver_cache); |
[email protected] | 367ead4 | 2010-02-26 00:15:21 | [diff] [blame] | 771 | |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 772 | int rv; |
| 773 | if (proxy_mode_ != kSOCKSProxy) { |
| 774 | rv = connection_->Init(connection_group, tcp_params, request_->priority, |
| 775 | &io_callback_, session_->tcp_socket_pool(), |
| 776 | net_log_); |
| 777 | } else { |
| 778 | bool socks_v5 = proxy_info_.proxy_server().scheme() == |
| 779 | ProxyServer::SCHEME_SOCKS5; |
| 780 | SOCKSSocketParams socks_params(tcp_params, socks_v5, |
| 781 | request_->url.HostNoBrackets(), |
| 782 | request_->url.EffectiveIntPort(), |
| 783 | request_->priority, request_->referrer); |
| 784 | |
| 785 | rv = connection_->Init(connection_group, socks_params, request_->priority, |
| 786 | &io_callback_, session_->socks_socket_pool(), |
| 787 | net_log_); |
| 788 | } |
| 789 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 790 | return rv; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | int HttpNetworkTransaction::DoInitConnectionComplete(int result) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 794 | if (result < 0) { |
| 795 | if (alternate_protocol_mode_ == kUsingAlternateProtocol) { |
| 796 | // Mark the alternate protocol as broken and fallback. |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 797 | MarkBrokenAlternateProtocolAndFallback(); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 798 | return OK; |
| 799 | } |
| 800 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 801 | return ReconsiderProxyAfterError(result); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 802 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 803 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 804 | DCHECK_EQ(OK, result); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 805 | |
[email protected] | e099391 | 2010-02-22 23:57:11 | [diff] [blame] | 806 | if (using_spdy_) { |
| 807 | DCHECK(!connection_->is_initialized()); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 808 | next_state_ = STATE_SPDY_SEND_REQUEST; |
| 809 | return OK; |
| 810 | } |
| 811 | |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 812 | LogHttpConnectedMetrics(*connection_); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 813 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 814 | // Set the reused_socket_ flag to indicate that we are using a keep-alive |
| 815 | // connection. This flag is used to handle errors that occur while we are |
| 816 | // trying to reuse a keep-alive connection. |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 817 | reused_socket_ = connection_->is_reused(); |
[email protected] | 049d4ee | 2008-10-23 21:42:07 | [diff] [blame] | 818 | if (reused_socket_) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 819 | next_state_ = STATE_SEND_REQUEST; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 820 | } else { |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 821 | // Now we have a TCP connected socket. Perform other connection setup as |
| 822 | // needed. |
[email protected] | 616925a | 2010-03-02 19:02:38 | [diff] [blame] | 823 | UpdateConnectionTypeHistograms(CONNECTION_HTTP); |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 824 | if (using_ssl_ && (proxy_mode_ == kDirectConnection || |
| 825 | proxy_mode_ == kSOCKSProxy)) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 826 | next_state_ = STATE_SSL_CONNECT; |
| 827 | } else { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 828 | next_state_ = STATE_SEND_REQUEST; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 829 | if (proxy_mode_ == kHTTPProxyUsingTunnel) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 830 | establishing_tunnel_ = true; |
| 831 | } |
[email protected] | c7af8b2 | 2008-08-25 20:41:46 | [diff] [blame] | 832 | } |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 833 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 834 | return OK; |
[email protected] | c7af8b2 | 2008-08-25 20:41:46 | [diff] [blame] | 835 | } |
| 836 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 837 | int HttpNetworkTransaction::DoSSLConnect() { |
| 838 | next_state_ = STATE_SSL_CONNECT_COMPLETE; |
[email protected] | c7af8b2 | 2008-08-25 20:41:46 | [diff] [blame] | 839 | |
[email protected] | aeaca1f | 2010-04-20 22:05:21 | [diff] [blame] | 840 | if (ContainsKey(*g_tls_intolerant_servers, GetHostAndPort(request_->url))) { |
| 841 | LOG(WARNING) << "Falling back to SSLv3 because host is TLS intolerant: " |
| 842 | << GetHostAndPort(request_->url); |
| 843 | ssl_config_.tls1_enabled = false; |
| 844 | } |
| 845 | |
[email protected] | f6555ad | 2009-06-23 06:35:05 | [diff] [blame] | 846 | if (request_->load_flags & LOAD_VERIFY_EV_CERT) |
| 847 | ssl_config_.verify_ev_cert = true; |
| 848 | |
[email protected] | b7b7678 | 2009-09-11 00:31:43 | [diff] [blame] | 849 | ssl_connect_start_time_ = base::TimeTicks::Now(); |
| 850 | |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 851 | // Add a SSL socket on top of our existing transport socket. |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 852 | ClientSocket* s = connection_->release_socket(); |
[email protected] | 5695b8c | 2009-09-30 21:36:43 | [diff] [blame] | 853 | s = session_->socket_factory()->CreateSSLClientSocket( |
[email protected] | facc826 | 2009-05-16 00:01:00 | [diff] [blame] | 854 | s, request_->url.HostNoBrackets(), ssl_config_); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 855 | connection_->set_socket(s); |
[email protected] | a2006ece | 2010-04-23 16:44:02 | [diff] [blame^] | 856 | return connection_->socket()->Connect(&io_callback_); |
[email protected] | c7af8b2 | 2008-08-25 20:41:46 | [diff] [blame] | 857 | } |
| 858 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 859 | int HttpNetworkTransaction::DoSSLConnectComplete(int result) { |
[email protected] | 37a6792 | 2010-03-05 00:16:02 | [diff] [blame] | 860 | SSLClientSocket* ssl_socket = |
| 861 | reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
| 862 | |
| 863 | SSLClientSocket::NextProtoStatus status = |
| 864 | SSLClientSocket::kNextProtoUnsupported; |
| 865 | std::string proto; |
| 866 | // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket |
| 867 | // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
| 868 | // here, then we know that we called SSL_ImportFD. |
| 869 | if (result == OK || IsCertificateError(result)) |
| 870 | status = ssl_socket->GetNextProto(&proto); |
[email protected] | 37a6792 | 2010-03-05 00:16:02 | [diff] [blame] | 871 | using_spdy_ = (status == SSLClientSocket::kNextProtoNegotiated && |
[email protected] | 87f64d0 | 2010-04-19 21:39:26 | [diff] [blame] | 872 | SSLClientSocket::NextProtoFromString(proto) == |
| 873 | SSLClientSocket::kProtoSPDY1); |
[email protected] | 37a6792 | 2010-03-05 00:16:02 | [diff] [blame] | 874 | |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 875 | if (alternate_protocol_mode_ == kUsingAlternateProtocol && |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 876 | alternate_protocol_ == HttpAlternateProtocols::NPN_SPDY_1 && |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 877 | !using_spdy_) { |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 878 | // We tried using the NPN_SPDY_1 alternate protocol, but failed, so we |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 879 | // fallback. |
| 880 | MarkBrokenAlternateProtocolAndFallback(); |
| 881 | return OK; |
| 882 | } |
| 883 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 884 | if (IsCertificateError(result)) { |
[email protected] | d7660f1c6 | 2010-02-15 02:57:29 | [diff] [blame] | 885 | result = HandleCertificateError(result); |
[email protected] | fab9ca5 | 2010-02-19 23:14:48 | [diff] [blame] | 886 | if (result == OK && !connection_->socket()->IsConnectedAndIdle()) { |
| 887 | connection_->socket()->Disconnect(); |
| 888 | connection_->Reset(); |
| 889 | next_state_ = STATE_INIT_CONNECTION; |
| 890 | return result; |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 891 | } |
| 892 | } |
[email protected] | 771d0c2b | 2008-09-30 00:26:17 | [diff] [blame] | 893 | |
[email protected] | c5949a3 | 2008-10-08 17:28:23 | [diff] [blame] | 894 | if (result == OK) { |
[email protected] | b7b7678 | 2009-09-11 00:31:43 | [diff] [blame] | 895 | DCHECK(ssl_connect_start_time_ != base::TimeTicks()); |
| 896 | base::TimeDelta connect_duration = |
| 897 | base::TimeTicks::Now() - ssl_connect_start_time_; |
| 898 | |
[email protected] | e099391 | 2010-02-22 23:57:11 | [diff] [blame] | 899 | if (using_spdy_) { |
[email protected] | 6aad1f60 | 2010-01-13 23:17:05 | [diff] [blame] | 900 | UMA_HISTOGRAM_CUSTOM_TIMES("Net.SpdyConnectionLatency", |
| 901 | connect_duration, |
| 902 | base::TimeDelta::FromMilliseconds(1), |
| 903 | base::TimeDelta::FromMinutes(10), |
| 904 | 100); |
| 905 | |
[email protected] | 616925a | 2010-03-02 19:02:38 | [diff] [blame] | 906 | UpdateConnectionTypeHistograms(CONNECTION_SPDY); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 907 | next_state_ = STATE_SPDY_SEND_REQUEST; |
| 908 | } else { |
[email protected] | 6aad1f60 | 2010-01-13 23:17:05 | [diff] [blame] | 909 | UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency", |
| 910 | connect_duration, |
| 911 | base::TimeDelta::FromMilliseconds(1), |
| 912 | base::TimeDelta::FromMinutes(10), |
| 913 | 100); |
| 914 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 915 | next_state_ = STATE_SEND_REQUEST; |
| 916 | } |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 917 | } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 918 | result = HandleCertificateRequest(result); |
[email protected] | 5a179bcc | 2008-10-13 18:10:59 | [diff] [blame] | 919 | } else { |
[email protected] | c5949a3 | 2008-10-08 17:28:23 | [diff] [blame] | 920 | result = HandleSSLHandshakeError(result); |
| 921 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 922 | return result; |
| 923 | } |
| 924 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 925 | int HttpNetworkTransaction::DoSendRequest() { |
| 926 | next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 927 | |
| 928 | UploadDataStream* request_body = NULL; |
[email protected] | 7a6db402 | 2010-03-24 23:37:50 | [diff] [blame] | 929 | if (!establishing_tunnel_ && request_->upload_data) { |
| 930 | int error_code; |
| 931 | request_body = UploadDataStream::Create(request_->upload_data, &error_code); |
| 932 | if (!request_body) |
| 933 | return error_code; |
| 934 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 935 | |
| 936 | // This is constructed lazily (instead of within our Start method), so that |
| 937 | // we have proxy info available. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 938 | if (request_headers_.empty()) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 939 | // Figure out if we can/should add Proxy-Authentication & Authentication |
| 940 | // headers. |
| 941 | bool have_proxy_auth = |
| 942 | ShouldApplyProxyAuth() && |
| 943 | (HaveAuth(HttpAuth::AUTH_PROXY) || |
| 944 | SelectPreemptiveAuth(HttpAuth::AUTH_PROXY)); |
| 945 | bool have_server_auth = |
| 946 | ShouldApplyServerAuth() && |
| 947 | (HaveAuth(HttpAuth::AUTH_SERVER) || |
| 948 | SelectPreemptiveAuth(HttpAuth::AUTH_SERVER)); |
| 949 | |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 950 | std::string request_line; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 951 | HttpRequestHeaders request_headers; |
| 952 | HttpRequestHeaders authorization_headers; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 953 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 954 | // TODO(wtc): If BuildAuthorizationHeader fails (returns an authorization |
| 955 | // header with no credentials), we should return an error to prevent |
| 956 | // entering an infinite auth restart loop. See http://crbug.com/21050. |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 957 | if (have_proxy_auth) |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 958 | AddAuthorizationHeader(HttpAuth::AUTH_PROXY, &authorization_headers); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 959 | if (have_server_auth) |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 960 | AddAuthorizationHeader(HttpAuth::AUTH_SERVER, &authorization_headers); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 961 | |
[email protected] | 6b9833e | 2008-09-10 20:32:25 | [diff] [blame] | 962 | if (establishing_tunnel_) { |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 963 | BuildTunnelRequest(request_, authorization_headers, &request_line, |
| 964 | &request_headers); |
[email protected] | 6b9833e | 2008-09-10 20:32:25 | [diff] [blame] | 965 | } else { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 966 | BuildRequestHeaders(request_, authorization_headers, request_body, |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 967 | proxy_mode_ == kHTTPProxy, &request_line, |
| 968 | &request_headers); |
[email protected] | 6b9833e | 2008-09-10 20:32:25 | [diff] [blame] | 969 | } |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 970 | |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 971 | request_headers_ = request_line + request_headers.ToString(); |
[email protected] | 6b9833e | 2008-09-10 20:32:25 | [diff] [blame] | 972 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 973 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 974 | headers_valid_ = false; |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 975 | http_stream_.reset(new HttpBasicStream(connection_.get(), net_log_)); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 976 | |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 977 | return http_stream_->SendRequest(request_, request_headers_, |
| 978 | request_body, &response_, &io_callback_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 979 | } |
| 980 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 981 | int HttpNetworkTransaction::DoSendRequestComplete(int result) { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 982 | if (result < 0) |
| 983 | return HandleIOError(result); |
| 984 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 985 | next_state_ = STATE_READ_HEADERS; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 986 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 987 | return OK; |
| 988 | } |
| 989 | |
| 990 | int HttpNetworkTransaction::DoReadHeaders() { |
| 991 | next_state_ = STATE_READ_HEADERS_COMPLETE; |
| 992 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 993 | return http_stream_->ReadResponseHeaders(&io_callback_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 994 | } |
| 995 | |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 996 | int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() { |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 997 | if (establishing_tunnel_) { |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 998 | // The connection was closed before the tunnel could be established. |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 999 | return ERR_TUNNEL_CONNECTION_FAILED; |
| 1000 | } |
| 1001 | |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1002 | if (!response_.headers) { |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 1003 | // The connection was closed before any data was sent. Likely an error |
| 1004 | // rather than empty HTTP/0.9 response. |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 1005 | return ERR_EMPTY_RESPONSE; |
| 1006 | } |
| 1007 | |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 1008 | return OK; |
| 1009 | } |
| 1010 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1011 | int HttpNetworkTransaction::DoReadHeadersComplete(int result) { |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 1012 | // We can get a certificate error or ERR_SSL_CLIENT_AUTH_CERT_NEEDED here |
| 1013 | // due to SSL renegotiation. |
| 1014 | if (using_ssl_) { |
| 1015 | if (IsCertificateError(result)) { |
| 1016 | // We don't handle a certificate error during SSL renegotiation, so we |
| 1017 | // have to return an error that's not in the certificate error range |
| 1018 | // (-2xx). |
| 1019 | LOG(ERROR) << "Got a server certificate with error " << result |
| 1020 | << " during SSL renegotiation"; |
| 1021 | result = ERR_CERT_ERROR_IN_SSL_RENEGOTIATION; |
| 1022 | } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 1023 | result = HandleCertificateRequest(result); |
| 1024 | if (result == OK) |
| 1025 | return result; |
[email protected] | aeaca1f | 2010-04-20 22:05:21 | [diff] [blame] | 1026 | } else if (result == ERR_SSL_DECOMPRESSION_FAILURE_ALERT && |
| 1027 | ssl_config_.tls1_enabled) { |
| 1028 | // Some buggy servers select DEFLATE compression when offered and then |
| 1029 | // fail to ever decompress anything. They will send a fatal alert telling |
| 1030 | // us this. Normally we would pick this up during the handshake because |
| 1031 | // our Finished message is compressed and we'll never get the server's |
| 1032 | // Finished if it fails to process ours. |
| 1033 | // |
| 1034 | // However, with False Start, we'll believe that the handshake is |
| 1035 | // complete as soon as we've /sent/ our Finished message. In this case, |
| 1036 | // we only find out that the server is buggy here, when we try to read |
| 1037 | // the initial reply. |
| 1038 | g_tls_intolerant_servers->insert(GetHostAndPort(request_->url)); |
| 1039 | ResetConnectionAndRequestForResend(); |
| 1040 | return OK; |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 1041 | } |
[email protected] | 2181ea00 | 2009-06-09 01:37:27 | [diff] [blame] | 1042 | } |
| 1043 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1044 | if (result < 0 && result != ERR_CONNECTION_CLOSED) |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1045 | return HandleIOError(result); |
| 1046 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1047 | if (result == ERR_CONNECTION_CLOSED && ShouldResendRequest(result)) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1048 | ResetConnectionAndRequestForResend(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1049 | return OK; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1050 | } |
[email protected] | 2a5c76b | 2008-09-25 22:15:16 | [diff] [blame] | 1051 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1052 | // After we call RestartWithAuth a new response_time will be recorded, and |
| 1053 | // we need to be cautious about incorrectly logging the duration across the |
| 1054 | // authentication activity. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1055 | if (!logged_response_time) { |
| 1056 | LogTransactionConnectedMetrics(); |
| 1057 | logged_response_time = true; |
[email protected] | 9a0a55f | 2009-04-13 23:23:03 | [diff] [blame] | 1058 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1059 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1060 | if (result == ERR_CONNECTION_CLOSED) { |
[email protected] | 02c92c49 | 2010-03-08 21:28:14 | [diff] [blame] | 1061 | // For now, if we get at least some data, we do the best we can to make |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 1062 | // sense of it and send it back up the stack. |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 1063 | int rv = HandleConnectionClosedBeforeEndOfHeaders(); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 1064 | if (rv != OK) |
| 1065 | return rv; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1066 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1067 | |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1068 | if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1069 | // Require the "HTTP/1.x" status line for SSL CONNECT. |
| 1070 | if (establishing_tunnel_) |
| 1071 | return ERR_TUNNEL_CONNECTION_FAILED; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1072 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1073 | // HTTP/0.9 doesn't support the PUT method, so lack of response headers |
| 1074 | // indicates a buggy server. See: |
| 1075 | // https://bugzilla.mozilla.org/show_bug.cgi?id=193921 |
| 1076 | if (request_->method == "PUT") |
| 1077 | return ERR_METHOD_NOT_SUPPORTED; |
| 1078 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 1079 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1080 | if (establishing_tunnel_) { |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1081 | switch (response_.headers->response_code()) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1082 | case 200: // OK |
| 1083 | if (http_stream_->IsMoreDataBuffered()) { |
| 1084 | // The proxy sent extraneous data after the headers. |
| 1085 | return ERR_TUNNEL_CONNECTION_FAILED; |
| 1086 | } |
| 1087 | next_state_ = STATE_SSL_CONNECT; |
| 1088 | // Reset for the real request and response headers. |
| 1089 | request_headers_.clear(); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 1090 | http_stream_.reset(new HttpBasicStream(connection_.get(), net_log_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1091 | headers_valid_ = false; |
| 1092 | establishing_tunnel_ = false; |
[email protected] | 5d0429b | 2010-04-02 15:46:11 | [diff] [blame] | 1093 | // TODO(mbelshe): We should put in a test case to trip this code path. |
| 1094 | response_ = HttpResponseInfo(); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1095 | return OK; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1096 | |
| 1097 | // We aren't able to CONNECT to the remote host through the proxy. We |
| 1098 | // need to be very suspicious about the response because an active network |
| 1099 | // attacker can force us into this state by masquerading as the proxy. |
| 1100 | // The only safe thing to do here is to fail the connection because our |
| 1101 | // client is expecting an SSL protected response. |
| 1102 | // See http://crbug.com/7338. |
| 1103 | case 407: // Proxy Authentication Required |
| 1104 | // We need this status code to allow proxy authentication. Our |
| 1105 | // authentication code is smart enough to avoid being tricked by an |
| 1106 | // active network attacker. |
| 1107 | break; |
| 1108 | default: |
| 1109 | // For all other status codes, we conservatively fail the CONNECT |
| 1110 | // request. |
| 1111 | // We lose something by doing this. We have seen proxy 403, 404, and |
| 1112 | // 501 response bodies that contain a useful error message. For |
| 1113 | // example, Squid uses a 404 response to report the DNS error: "The |
| 1114 | // domain name does not exist." |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1115 | LogBlockedTunnelResponse(response_.headers->response_code()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1116 | return ERR_TUNNEL_CONNECTION_FAILED; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1117 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1118 | } |
[email protected] | 65f1140 | 2008-10-31 17:39:44 | [diff] [blame] | 1119 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1120 | // Check for an intermediate 100 Continue response. An origin server is |
| 1121 | // allowed to send this response even if we didn't ask for it, so we just |
| 1122 | // need to skip over it. |
| 1123 | // We treat any other 1xx in this same way (although in practice getting |
| 1124 | // a 1xx that isn't a 100 is rare). |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1125 | if (response_.headers->response_code() / 100 == 1) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1126 | response_.headers = new HttpResponseHeaders(""); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1127 | next_state_ = STATE_READ_HEADERS; |
| 1128 | return OK; |
| 1129 | } |
| 1130 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 1131 | HostPortPair http_host_port_pair; |
| 1132 | http_host_port_pair.host = request_->url.host(); |
| 1133 | http_host_port_pair.port = request_->url.EffectiveIntPort(); |
| 1134 | |
| 1135 | ProcessAlternateProtocol(*response_.headers, |
| 1136 | http_host_port_pair, |
| 1137 | session_->mutable_alternate_protocols()); |
| 1138 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1139 | int rv = HandleAuthChallenge(); |
| 1140 | if (rv != OK) |
| 1141 | return rv; |
| 1142 | |
| 1143 | if (using_ssl_ && !establishing_tunnel_) { |
| 1144 | SSLClientSocket* ssl_socket = |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1145 | reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1146 | ssl_socket->GetSSLInfo(&response_.ssl_info); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | headers_valid_ = true; |
| 1150 | return OK; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1151 | } |
| 1152 | |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 1153 | int HttpNetworkTransaction::DoResolveCanonicalName() { |
| 1154 | HttpAuthHandler* auth_handler = auth_handler_[pending_auth_target_]; |
| 1155 | DCHECK(auth_handler); |
| 1156 | next_state_ = STATE_RESOLVE_CANONICAL_NAME_COMPLETE; |
| 1157 | return auth_handler->ResolveCanonicalName(session_->host_resolver(), |
| 1158 | &io_callback_, net_log_); |
| 1159 | } |
| 1160 | |
| 1161 | int HttpNetworkTransaction::DoResolveCanonicalNameComplete(int result) { |
| 1162 | // The STATE_RESOLVE_CANONICAL_NAME state ends the Start sequence when the |
| 1163 | // canonical name of the server needs to be determined. Normally |
| 1164 | // DoReadHeadersComplete completes the sequence. The next state is |
| 1165 | // intentionally not set as it should be STATE_NONE; |
| 1166 | DCHECK_EQ(STATE_NONE, next_state_); |
| 1167 | return result; |
| 1168 | } |
| 1169 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | int HttpNetworkTransaction::DoReadBody() { |
| 1171 | DCHECK(read_buf_); |
[email protected] | 6501bc0 | 2009-06-25 20:55:13 | [diff] [blame] | 1172 | DCHECK_GT(read_buf_len_, 0); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1173 | DCHECK(connection_->is_initialized()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1174 | |
| 1175 | next_state_ = STATE_READ_BODY_COMPLETE; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1176 | return http_stream_->ReadResponseBody(read_buf_, read_buf_len_, |
| 1177 | &io_callback_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | int HttpNetworkTransaction::DoReadBodyComplete(int result) { |
| 1181 | // We are done with the Read call. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1182 | DCHECK(!establishing_tunnel_) << |
| 1183 | "We should never read a response body of a tunnel."; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1184 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1185 | bool done = false, keep_alive = false; |
[email protected] | 02c92c49 | 2010-03-08 21:28:14 | [diff] [blame] | 1186 | if (result <= 0) |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1187 | done = true; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 1188 | |
| 1189 | if (http_stream_->IsResponseBodyComplete()) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1190 | done = true; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 1191 | if (http_stream_->CanFindEndOfResponse()) |
[email protected] | 02c92c49 | 2010-03-08 21:28:14 | [diff] [blame] | 1192 | keep_alive = GetResponseHeaders()->IsKeepAlive(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1193 | } |
| 1194 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1195 | // Clean up connection_->if we are done. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1196 | if (done) { |
[email protected] | 5630017 | 2008-11-06 18:42:55 | [diff] [blame] | 1197 | LogTransactionMetrics(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1198 | if (!keep_alive) |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1199 | connection_->socket()->Disconnect(); |
| 1200 | connection_->Reset(); |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 1201 | // The next Read call will return 0 (EOF). |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | // Clear these to avoid leaving around old state. |
| 1205 | read_buf_ = NULL; |
| 1206 | read_buf_len_ = 0; |
| 1207 | |
| 1208 | return result; |
| 1209 | } |
| 1210 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1211 | int HttpNetworkTransaction::DoDrainBodyForAuthRestart() { |
| 1212 | // This method differs from DoReadBody only in the next_state_. So we just |
| 1213 | // call DoReadBody and override the next_state_. Perhaps there is a more |
| 1214 | // elegant way for these two methods to share code. |
| 1215 | int rv = DoReadBody(); |
| 1216 | DCHECK(next_state_ == STATE_READ_BODY_COMPLETE); |
| 1217 | next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE; |
| 1218 | return rv; |
| 1219 | } |
| 1220 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1221 | // TODO(wtc): This method and the DoReadBodyComplete method are almost |
| 1222 | // the same. Figure out a good way for these two methods to share code. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1223 | int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { |
[email protected] | 68873ba | 2009-06-04 21:49:23 | [diff] [blame] | 1224 | // keep_alive defaults to true because the very reason we're draining the |
| 1225 | // response body is to reuse the connection for auth restart. |
| 1226 | bool done = false, keep_alive = true; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1227 | if (result < 0) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1228 | // Error or closed connection while reading the socket. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1229 | done = true; |
[email protected] | 68873ba | 2009-06-04 21:49:23 | [diff] [blame] | 1230 | keep_alive = false; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1231 | } else if (http_stream_->IsResponseBodyComplete()) { |
| 1232 | done = true; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | if (done) { |
| 1236 | DidDrainBodyForAuthRestart(keep_alive); |
| 1237 | } else { |
| 1238 | // Keep draining. |
| 1239 | next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; |
| 1240 | } |
| 1241 | |
| 1242 | return OK; |
| 1243 | } |
| 1244 | |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1245 | int HttpNetworkTransaction::DoSpdySendRequest() { |
| 1246 | next_state_ = STATE_SPDY_SEND_REQUEST_COMPLETE; |
| 1247 | CHECK(!spdy_stream_.get()); |
| 1248 | |
| 1249 | // First we get a SPDY session. Theoretically, we've just negotiated one, but |
| 1250 | // if one already exists, then screw it, use the existing one! Otherwise, |
| 1251 | // use the existing TCP socket. |
| 1252 | |
[email protected] | 367ead4 | 2010-02-26 00:15:21 | [diff] [blame] | 1253 | HostPortPair host_port_pair(request_->url.HostNoBrackets(), |
| 1254 | request_->url.EffectiveIntPort()); |
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 1255 | const scoped_refptr<SpdySessionPool> spdy_pool = |
| 1256 | session_->spdy_session_pool(); |
| 1257 | scoped_refptr<SpdySession> spdy_session; |
[email protected] | 5e2e6c77d1 | 2009-12-24 21:57:16 | [diff] [blame] | 1258 | |
[email protected] | 367ead4 | 2010-02-26 00:15:21 | [diff] [blame] | 1259 | if (spdy_pool->HasSession(host_port_pair)) { |
| 1260 | spdy_session = spdy_pool->Get(host_port_pair, session_); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1261 | } else { |
[email protected] | 5fe524e | 2010-02-20 00:43:22 | [diff] [blame] | 1262 | // SPDY is negotiated using the TLS next protocol negotiation (NPN) |
| 1263 | // extension, so |connection_| must contain an SSLClientSocket. |
| 1264 | DCHECK(using_ssl_); |
| 1265 | spdy_session = spdy_pool->GetSpdySessionFromSSLSocket( |
[email protected] | 367ead4 | 2010-02-26 00:15:21 | [diff] [blame] | 1266 | host_port_pair, session_, connection_.release()); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | CHECK(spdy_session.get()); |
| 1270 | |
[email protected] | 7a6db402 | 2010-03-24 23:37:50 | [diff] [blame] | 1271 | UploadDataStream* upload_data = NULL; |
| 1272 | if (request_->upload_data) { |
| 1273 | int error_code = OK; |
| 1274 | upload_data = UploadDataStream::Create(request_->upload_data, &error_code); |
| 1275 | if (!upload_data) |
| 1276 | return error_code; |
| 1277 | } |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1278 | headers_valid_ = false; |
| 1279 | spdy_stream_ = spdy_session->GetOrCreateStream( |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 1280 | *request_, upload_data, net_log_); |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1281 | return spdy_stream_->SendRequest(upload_data, &response_, &io_callback_); |
| 1282 | } |
| 1283 | |
| 1284 | int HttpNetworkTransaction::DoSpdySendRequestComplete(int result) { |
| 1285 | if (result < 0) |
| 1286 | return result; |
| 1287 | |
| 1288 | next_state_ = STATE_SPDY_READ_HEADERS; |
| 1289 | return OK; |
| 1290 | } |
| 1291 | |
| 1292 | int HttpNetworkTransaction::DoSpdyReadHeaders() { |
| 1293 | next_state_ = STATE_SPDY_READ_HEADERS_COMPLETE; |
| 1294 | return spdy_stream_->ReadResponseHeaders(&io_callback_); |
| 1295 | } |
| 1296 | |
| 1297 | int HttpNetworkTransaction::DoSpdyReadHeadersComplete(int result) { |
| 1298 | // TODO(willchan): Flesh out the support for HTTP authentication here. |
| 1299 | if (result == OK) |
| 1300 | headers_valid_ = true; |
| 1301 | return result; |
| 1302 | } |
| 1303 | |
| 1304 | int HttpNetworkTransaction::DoSpdyReadBody() { |
| 1305 | next_state_ = STATE_SPDY_READ_BODY_COMPLETE; |
| 1306 | |
| 1307 | return spdy_stream_->ReadResponseBody( |
| 1308 | read_buf_, read_buf_len_, &io_callback_); |
| 1309 | } |
| 1310 | |
| 1311 | int HttpNetworkTransaction::DoSpdyReadBodyComplete(int result) { |
| 1312 | read_buf_ = NULL; |
| 1313 | read_buf_len_ = 0; |
| 1314 | |
| 1315 | if (result <= 0) |
| 1316 | spdy_stream_ = NULL; |
| 1317 | |
| 1318 | return result; |
| 1319 | } |
| 1320 | |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 1321 | void HttpNetworkTransaction::LogHttpConnectedMetrics( |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 1322 | const ClientSocketHandle& handle) { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 1323 | UMA_HISTOGRAM_ENUMERATION("Net.HttpSocketType", handle.reuse_type(), |
[email protected] | 2753b39 | 2009-12-28 06:59:52 | [diff] [blame] | 1324 | ClientSocketHandle::NUM_TYPES); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 1325 | |
[email protected] | bc3875bbc | 2009-08-24 19:44:20 | [diff] [blame] | 1326 | switch (handle.reuse_type()) { |
| 1327 | case ClientSocketHandle::UNUSED: |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 1328 | UMA_HISTOGRAM_CUSTOM_TIMES("Net.HttpConnectionLatency", |
| 1329 | handle.setup_time(), |
| 1330 | base::TimeDelta::FromMilliseconds(1), |
| 1331 | base::TimeDelta::FromMinutes(10), |
| 1332 | 100); |
[email protected] | bc3875bbc | 2009-08-24 19:44:20 | [diff] [blame] | 1333 | break; |
| 1334 | case ClientSocketHandle::UNUSED_IDLE: |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 1335 | UMA_HISTOGRAM_CUSTOM_TIMES("Net.SocketIdleTimeBeforeNextUse_UnusedSocket", |
| 1336 | handle.idle_time(), |
| 1337 | base::TimeDelta::FromMilliseconds(1), |
| 1338 | base::TimeDelta::FromMinutes(6), |
| 1339 | 100); |
[email protected] | bc3875bbc | 2009-08-24 19:44:20 | [diff] [blame] | 1340 | break; |
| 1341 | case ClientSocketHandle::REUSED_IDLE: |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 1342 | UMA_HISTOGRAM_CUSTOM_TIMES("Net.SocketIdleTimeBeforeNextUse_ReusedSocket", |
| 1343 | handle.idle_time(), |
| 1344 | base::TimeDelta::FromMilliseconds(1), |
| 1345 | base::TimeDelta::FromMinutes(6), |
| 1346 | 100); |
[email protected] | bc3875bbc | 2009-08-24 19:44:20 | [diff] [blame] | 1347 | break; |
| 1348 | default: |
| 1349 | NOTREACHED(); |
| 1350 | break; |
| 1351 | } |
[email protected] | 42afa7c | 2009-04-17 23:51:24 | [diff] [blame] | 1352 | } |
| 1353 | |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 1354 | void HttpNetworkTransaction::LogIOErrorMetrics( |
| 1355 | const ClientSocketHandle& handle) { |
[email protected] | 2753b39 | 2009-12-28 06:59:52 | [diff] [blame] | 1356 | UMA_HISTOGRAM_ENUMERATION("Net.IOError_SocketReuseType", |
| 1357 | handle.reuse_type(), ClientSocketHandle::NUM_TYPES); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 1358 | |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 1359 | switch (handle.reuse_type()) { |
| 1360 | case ClientSocketHandle::UNUSED: |
| 1361 | break; |
| 1362 | case ClientSocketHandle::UNUSED_IDLE: |
[email protected] | bc3875bbc | 2009-08-24 19:44:20 | [diff] [blame] | 1363 | UMA_HISTOGRAM_CUSTOM_TIMES( |
| 1364 | "Net.SocketIdleTimeOnIOError2_UnusedSocket", |
| 1365 | handle.idle_time(), base::TimeDelta::FromMilliseconds(1), |
| 1366 | base::TimeDelta::FromMinutes(6), 100); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 1367 | break; |
| 1368 | case ClientSocketHandle::REUSED_IDLE: |
[email protected] | bc3875bbc | 2009-08-24 19:44:20 | [diff] [blame] | 1369 | UMA_HISTOGRAM_CUSTOM_TIMES( |
| 1370 | "Net.SocketIdleTimeOnIOError2_ReusedSocket", |
| 1371 | handle.idle_time(), base::TimeDelta::FromMilliseconds(1), |
| 1372 | base::TimeDelta::FromMinutes(6), 100); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 1373 | break; |
| 1374 | default: |
| 1375 | NOTREACHED(); |
| 1376 | break; |
| 1377 | } |
| 1378 | } |
| 1379 | |
[email protected] | 9a0a55f | 2009-04-13 23:23:03 | [diff] [blame] | 1380 | void HttpNetworkTransaction::LogTransactionConnectedMetrics() const { |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1381 | base::TimeDelta total_duration = response_.response_time - start_time_; |
[email protected] | 9a0a55f | 2009-04-13 23:23:03 | [diff] [blame] | 1382 | |
[email protected] | 510e854f | 2009-04-20 18:39:08 | [diff] [blame] | 1383 | UMA_HISTOGRAM_CLIPPED_TIMES( |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1384 | "Net.Transaction_Connected_Under_10", |
[email protected] | 510e854f | 2009-04-20 18:39:08 | [diff] [blame] | 1385 | total_duration, |
[email protected] | 9a0a55f | 2009-04-13 23:23:03 | [diff] [blame] | 1386 | base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10), |
| 1387 | 100); |
[email protected] | 1fa4759 | 2009-07-27 22:45:00 | [diff] [blame] | 1388 | |
[email protected] | 0310d43 | 2009-08-25 07:49:52 | [diff] [blame] | 1389 | if (!reused_socket_) { |
[email protected] | b01998a | 2009-04-21 01:01:11 | [diff] [blame] | 1390 | UMA_HISTOGRAM_CLIPPED_TIMES( |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1391 | "Net.Transaction_Connected_New", |
[email protected] | b01998a | 2009-04-21 01:01:11 | [diff] [blame] | 1392 | total_duration, |
| 1393 | base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10), |
| 1394 | 100); |
[email protected] | 0310d43 | 2009-08-25 07:49:52 | [diff] [blame] | 1395 | } |
| 1396 | |
[email protected] | 510e854f | 2009-04-20 18:39:08 | [diff] [blame] | 1397 | // Currently, non-zero priority requests are frame or sub-frame resource |
| 1398 | // types. This will change when we also prioritize certain subresources like |
| 1399 | // css, js, etc. |
| 1400 | if (request_->priority) { |
| 1401 | UMA_HISTOGRAM_CLIPPED_TIMES( |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1402 | "Net.Priority_High_Latency", |
[email protected] | 510e854f | 2009-04-20 18:39:08 | [diff] [blame] | 1403 | total_duration, |
| 1404 | base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10), |
| 1405 | 100); |
| 1406 | } else { |
| 1407 | UMA_HISTOGRAM_CLIPPED_TIMES( |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1408 | "Net.Priority_Low_Latency", |
[email protected] | 510e854f | 2009-04-20 18:39:08 | [diff] [blame] | 1409 | total_duration, |
| 1410 | base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10), |
| 1411 | 100); |
| 1412 | } |
[email protected] | 9a0a55f | 2009-04-13 23:23:03 | [diff] [blame] | 1413 | } |
| 1414 | |
[email protected] | 5630017 | 2008-11-06 18:42:55 | [diff] [blame] | 1415 | void HttpNetworkTransaction::LogTransactionMetrics() const { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1416 | base::TimeDelta duration = base::Time::Now() - |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1417 | response_.request_time; |
[email protected] | 5630017 | 2008-11-06 18:42:55 | [diff] [blame] | 1418 | if (60 < duration.InMinutes()) |
| 1419 | return; |
[email protected] | 0b48db4 | 2009-03-23 02:45:11 | [diff] [blame] | 1420 | |
[email protected] | 21b316a | 2009-03-23 18:25:06 | [diff] [blame] | 1421 | base::TimeDelta total_duration = base::Time::Now() - start_time_; |
| 1422 | |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1423 | UMA_HISTOGRAM_LONG_TIMES("Net.Transaction_Latency", duration); |
| 1424 | UMA_HISTOGRAM_CLIPPED_TIMES("Net.Transaction_Latency_Under_10", duration, |
[email protected] | 0b48db4 | 2009-03-23 02:45:11 | [diff] [blame] | 1425 | base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10), |
| 1426 | 100); |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1427 | UMA_HISTOGRAM_CLIPPED_TIMES("Net.Transaction_Latency_Total_Under_10", |
[email protected] | 21b316a | 2009-03-23 18:25:06 | [diff] [blame] | 1428 | total_duration, base::TimeDelta::FromMilliseconds(1), |
| 1429 | base::TimeDelta::FromMinutes(10), 100); |
[email protected] | 808f640 | 2009-03-30 20:02:07 | [diff] [blame] | 1430 | if (!reused_socket_) { |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1431 | UMA_HISTOGRAM_CLIPPED_TIMES( |
[email protected] | 808f640 | 2009-03-30 20:02:07 | [diff] [blame] | 1432 | "Net.Transaction_Latency_Total_New_Connection_Under_10", |
[email protected] | 808f640 | 2009-03-30 20:02:07 | [diff] [blame] | 1433 | total_duration, base::TimeDelta::FromMilliseconds(1), |
| 1434 | base::TimeDelta::FromMinutes(10), 100); |
| 1435 | } |
[email protected] | 5630017 | 2008-11-06 18:42:55 | [diff] [blame] | 1436 | } |
| 1437 | |
[email protected] | 9f9f86c | 2009-03-12 22:32:42 | [diff] [blame] | 1438 | void HttpNetworkTransaction::LogBlockedTunnelResponse( |
[email protected] | af89ba6 | 2009-03-16 20:26:38 | [diff] [blame] | 1439 | int response_code) const { |
| 1440 | LOG(WARNING) << "Blocked proxy response with status " << response_code |
[email protected] | 71e4573a | 2009-05-21 22:03:00 | [diff] [blame] | 1441 | << " to CONNECT request for " |
| 1442 | << GetHostAndPort(request_->url) << "."; |
[email protected] | 9f9f86c | 2009-03-12 22:32:42 | [diff] [blame] | 1443 | } |
| 1444 | |
[email protected] | ccb40e5 | 2008-09-17 20:54:40 | [diff] [blame] | 1445 | int HttpNetworkTransaction::HandleCertificateError(int error) { |
| 1446 | DCHECK(using_ssl_); |
[email protected] | d7660f1c6 | 2010-02-15 02:57:29 | [diff] [blame] | 1447 | DCHECK(IsCertificateError(error)); |
| 1448 | |
| 1449 | SSLClientSocket* ssl_socket = |
| 1450 | reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
| 1451 | ssl_socket->GetSSLInfo(&response_.ssl_info); |
| 1452 | |
| 1453 | // Add the bad certificate to the set of allowed certificates in the |
| 1454 | // SSL info object. This data structure will be consulted after calling |
| 1455 | // RestartIgnoringLastError(). And the user will be asked interactively |
| 1456 | // before RestartIgnoringLastError() is ever called. |
| 1457 | SSLConfig::CertAndStatus bad_cert; |
| 1458 | bad_cert.cert = response_.ssl_info.cert; |
| 1459 | bad_cert.cert_status = response_.ssl_info.cert_status; |
| 1460 | ssl_config_.allowed_bad_certs.push_back(bad_cert); |
[email protected] | ccb40e5 | 2008-09-17 20:54:40 | [diff] [blame] | 1461 | |
[email protected] | 37a6792 | 2010-03-05 00:16:02 | [diff] [blame] | 1462 | if (g_ignore_certificate_errors) |
| 1463 | return OK; |
| 1464 | |
[email protected] | ccb40e5 | 2008-09-17 20:54:40 | [diff] [blame] | 1465 | const int kCertFlags = LOAD_IGNORE_CERT_COMMON_NAME_INVALID | |
| 1466 | LOAD_IGNORE_CERT_DATE_INVALID | |
| 1467 | LOAD_IGNORE_CERT_AUTHORITY_INVALID | |
| 1468 | LOAD_IGNORE_CERT_WRONG_USAGE; |
| 1469 | if (request_->load_flags & kCertFlags) { |
| 1470 | switch (error) { |
| 1471 | case ERR_CERT_COMMON_NAME_INVALID: |
| 1472 | if (request_->load_flags & LOAD_IGNORE_CERT_COMMON_NAME_INVALID) |
| 1473 | error = OK; |
| 1474 | break; |
| 1475 | case ERR_CERT_DATE_INVALID: |
| 1476 | if (request_->load_flags & LOAD_IGNORE_CERT_DATE_INVALID) |
| 1477 | error = OK; |
| 1478 | break; |
| 1479 | case ERR_CERT_AUTHORITY_INVALID: |
| 1480 | if (request_->load_flags & LOAD_IGNORE_CERT_AUTHORITY_INVALID) |
| 1481 | error = OK; |
| 1482 | break; |
| 1483 | } |
| 1484 | } |
[email protected] | ccb40e5 | 2008-09-17 20:54:40 | [diff] [blame] | 1485 | return error; |
| 1486 | } |
| 1487 | |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 1488 | int HttpNetworkTransaction::HandleCertificateRequest(int error) { |
| 1489 | // Assert that the socket did not send a client certificate. |
| 1490 | // Note: If we got a reused socket, it was created with some other |
| 1491 | // transaction's ssl_config_, so we need to disable this assertion. We can |
| 1492 | // get a certificate request on a reused socket when the server requested |
| 1493 | // renegotiation (rehandshake). |
| 1494 | // TODO(wtc): add a GetSSLParams method to SSLClientSocket so we can query |
| 1495 | // the SSL parameters it was created with and get rid of the reused_socket_ |
| 1496 | // test. |
| 1497 | DCHECK(reused_socket_ || !ssl_config_.send_client_cert); |
| 1498 | |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1499 | response_.cert_request_info = new SSLCertRequestInfo; |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 1500 | SSLClientSocket* ssl_socket = |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1501 | reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1502 | ssl_socket->GetSSLCertRequestInfo(response_.cert_request_info); |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 1503 | |
| 1504 | // Close the connection while the user is selecting a certificate to send |
| 1505 | // to the server. |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1506 | connection_->socket()->Disconnect(); |
| 1507 | connection_->Reset(); |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 1508 | |
| 1509 | // If the user selected one of the certificate in client_certs for this |
| 1510 | // server before, use it automatically. |
| 1511 | X509Certificate* client_cert = session_->ssl_client_auth_cache()-> |
| 1512 | Lookup(GetHostAndPort(request_->url)); |
| 1513 | if (client_cert) { |
| 1514 | const std::vector<scoped_refptr<X509Certificate> >& client_certs = |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1515 | response_.cert_request_info->client_certs; |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 1516 | for (size_t i = 0; i < client_certs.size(); ++i) { |
[email protected] | bd0b743 | 2009-06-23 21:03:42 | [diff] [blame] | 1517 | if (client_cert->fingerprint().Equals(client_certs[i]->fingerprint())) { |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 1518 | ssl_config_.client_cert = client_cert; |
| 1519 | ssl_config_.send_client_cert = true; |
| 1520 | next_state_ = STATE_INIT_CONNECTION; |
| 1521 | // Reset the other member variables. |
| 1522 | // Note: this is necessary only with SSL renegotiation. |
| 1523 | ResetStateForRestart(); |
| 1524 | return OK; |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | return error; |
[email protected] | 0b45559b | 2009-06-12 21:45:11 | [diff] [blame] | 1529 | } |
| 1530 | |
[email protected] | c5949a3 | 2008-10-08 17:28:23 | [diff] [blame] | 1531 | int HttpNetworkTransaction::HandleSSLHandshakeError(int error) { |
[email protected] | 5e36396 | 2009-06-19 19:57:01 | [diff] [blame] | 1532 | if (ssl_config_.send_client_cert && |
| 1533 | (error == ERR_SSL_PROTOCOL_ERROR || |
| 1534 | error == ERR_BAD_SSL_CLIENT_AUTH_CERT)) { |
| 1535 | session_->ssl_client_auth_cache()->Remove(GetHostAndPort(request_->url)); |
| 1536 | } |
| 1537 | |
[email protected] | 5a179bcc | 2008-10-13 18:10:59 | [diff] [blame] | 1538 | switch (error) { |
| 1539 | case ERR_SSL_PROTOCOL_ERROR: |
| 1540 | case ERR_SSL_VERSION_OR_CIPHER_MISMATCH: |
[email protected] | aeaca1f | 2010-04-20 22:05:21 | [diff] [blame] | 1541 | case ERR_SSL_DECOMPRESSION_FAILURE_ALERT: |
[email protected] | aaead50 | 2008-10-15 00:20:11 | [diff] [blame] | 1542 | if (ssl_config_.tls1_enabled) { |
[email protected] | 5a179bcc | 2008-10-13 18:10:59 | [diff] [blame] | 1543 | // This could be a TLS-intolerant server or an SSL 3.0 server that |
| 1544 | // chose a TLS-only cipher suite. Turn off TLS 1.0 and retry. |
[email protected] | aeaca1f | 2010-04-20 22:05:21 | [diff] [blame] | 1545 | g_tls_intolerant_servers->insert(GetHostAndPort(request_->url)); |
| 1546 | ResetConnectionAndRequestForResend(); |
[email protected] | 5a179bcc | 2008-10-13 18:10:59 | [diff] [blame] | 1547 | error = OK; |
| 1548 | } |
| 1549 | break; |
[email protected] | c5949a3 | 2008-10-08 17:28:23 | [diff] [blame] | 1550 | } |
[email protected] | c5949a3 | 2008-10-08 17:28:23 | [diff] [blame] | 1551 | return error; |
| 1552 | } |
| 1553 | |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 1554 | // This method determines whether it is safe to resend the request after an |
| 1555 | // IO error. It can only be called in response to request header or body |
| 1556 | // write errors or response header read errors. It should not be used in |
| 1557 | // other cases, such as a Connect error. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1558 | int HttpNetworkTransaction::HandleIOError(int error) { |
| 1559 | switch (error) { |
| 1560 | // If we try to reuse a connection that the server is in the process of |
| 1561 | // closing, we may end up successfully writing out our request (or a |
| 1562 | // portion of our request) only to find a connection error when we try to |
| 1563 | // read from (or finish writing to) the socket. |
| 1564 | case ERR_CONNECTION_RESET: |
| 1565 | case ERR_CONNECTION_CLOSED: |
| 1566 | case ERR_CONNECTION_ABORTED: |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1567 | LogIOErrorMetrics(*connection_); |
[email protected] | a19f1c60 | 2009-08-24 21:35:28 | [diff] [blame] | 1568 | if (ShouldResendRequest(error)) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1569 | ResetConnectionAndRequestForResend(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1570 | error = OK; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1571 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1572 | break; |
| 1573 | } |
| 1574 | return error; |
| 1575 | } |
| 1576 | |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1577 | void HttpNetworkTransaction::ResetStateForRestart() { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1578 | pending_auth_target_ = HttpAuth::AUTH_NONE; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1579 | read_buf_ = NULL; |
| 1580 | read_buf_len_ = 0; |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1581 | http_stream_.reset(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1582 | headers_valid_ = false; |
| 1583 | request_headers_.clear(); |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1584 | response_ = HttpResponseInfo(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1588 | return response_.headers; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1589 | } |
| 1590 | |
[email protected] | a19f1c60 | 2009-08-24 21:35:28 | [diff] [blame] | 1591 | bool HttpNetworkTransaction::ShouldResendRequest(int error) const { |
[email protected] | 2a5c76b | 2008-09-25 22:15:16 | [diff] [blame] | 1592 | // NOTE: we resend a request only if we reused a keep-alive connection. |
| 1593 | // This automatically prevents an infinite resend loop because we'll run |
| 1594 | // out of the cached keep-alive connections eventually. |
| 1595 | if (establishing_tunnel_ || |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1596 | !connection_->ShouldResendFailedRequest(error) || |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1597 | GetResponseHeaders()) { // We have received some response headers. |
[email protected] | 2a5c76b | 2008-09-25 22:15:16 | [diff] [blame] | 1598 | return false; |
| 1599 | } |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1600 | return true; |
| 1601 | } |
| 1602 | |
| 1603 | void HttpNetworkTransaction::ResetConnectionAndRequestForResend() { |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1604 | connection_->socket()->Disconnect(); |
| 1605 | connection_->Reset(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1606 | // We need to clear request_headers_ because it contains the real request |
| 1607 | // headers, but we may need to resend the CONNECT request first to recreate |
| 1608 | // the SSL tunnel. |
| 1609 | request_headers_.clear(); |
[email protected] | 2a5c76b | 2008-09-25 22:15:16 | [diff] [blame] | 1610 | next_state_ = STATE_INIT_CONNECTION; // Resend the request. |
[email protected] | 2a5c76b | 2008-09-25 22:15:16 | [diff] [blame] | 1611 | } |
| 1612 | |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1613 | int HttpNetworkTransaction::ReconsiderProxyAfterError(int error) { |
| 1614 | DCHECK(!pac_request_); |
| 1615 | |
| 1616 | // A failure to resolve the hostname or any error related to establishing a |
| 1617 | // TCP connection could be grounds for trying a new proxy configuration. |
[email protected] | 7be5131 | 2008-09-29 23:21:30 | [diff] [blame] | 1618 | // |
| 1619 | // Why do this when a hostname cannot be resolved? Some URLs only make sense |
| 1620 | // to proxy servers. The hostname in those URLs might fail to resolve if we |
| 1621 | // are still using a non-proxy config. We need to check if a proxy config |
| 1622 | // now exists that corresponds to a proxy server that could load the URL. |
| 1623 | // |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1624 | switch (error) { |
| 1625 | case ERR_NAME_NOT_RESOLVED: |
| 1626 | case ERR_INTERNET_DISCONNECTED: |
| 1627 | case ERR_ADDRESS_UNREACHABLE: |
| 1628 | case ERR_CONNECTION_CLOSED: |
| 1629 | case ERR_CONNECTION_RESET: |
| 1630 | case ERR_CONNECTION_REFUSED: |
| 1631 | case ERR_CONNECTION_ABORTED: |
| 1632 | case ERR_TIMED_OUT: |
| 1633 | case ERR_TUNNEL_CONNECTION_FAILED: |
[email protected] | d5a30959 | 2010-02-05 02:22:52 | [diff] [blame] | 1634 | case ERR_SOCKS_CONNECTION_FAILED: |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1635 | break; |
[email protected] | d5a30959 | 2010-02-05 02:22:52 | [diff] [blame] | 1636 | case ERR_SOCKS_CONNECTION_HOST_UNREACHABLE: |
| 1637 | // Remap the SOCKS-specific "host unreachable" error to a more |
| 1638 | // generic error code (this way consumers like the link doctor |
| 1639 | // know to substitute their error page). |
| 1640 | // |
| 1641 | // Note that if the host resolving was done by the SOCSK5 proxy, we can't |
| 1642 | // differentiate between a proxy-side "host not found" versus a proxy-side |
| 1643 | // "address unreachable" error, and will report both of these failures as |
| 1644 | // ERR_ADDRESS_UNREACHABLE. |
| 1645 | return ERR_ADDRESS_UNREACHABLE; |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1646 | default: |
| 1647 | return error; |
| 1648 | } |
| 1649 | |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 1650 | if (request_->load_flags & LOAD_BYPASS_PROXY) { |
| 1651 | return error; |
| 1652 | } |
| 1653 | |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1654 | int rv = session_->proxy_service()->ReconsiderProxyAfterError( |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 1655 | request_->url, &proxy_info_, &io_callback_, &pac_request_, net_log_); |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1656 | if (rv == OK || rv == ERR_IO_PENDING) { |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 1657 | // If the error was during connection setup, there is no socket to |
| 1658 | // disconnect. |
[email protected] | 1f14a91 | 2009-12-21 20:32:44 | [diff] [blame] | 1659 | if (connection_->socket()) |
| 1660 | connection_->socket()->Disconnect(); |
| 1661 | connection_->Reset(); |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1662 | next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
| 1663 | } else { |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 1664 | // If ReconsiderProxyAfterError() failed synchronously, it means |
| 1665 | // there was nothing left to fall-back to, so fail the transaction |
| 1666 | // with the last connection error we got. |
| 1667 | // TODO(eroman): This is a confusing contract, make it more obvious. |
[email protected] | 86ec30d | 2008-09-29 21:53:54 | [diff] [blame] | 1668 | rv = error; |
| 1669 | } |
| 1670 | |
| 1671 | return rv; |
| 1672 | } |
| 1673 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1674 | bool HttpNetworkTransaction::ShouldApplyProxyAuth() const { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 1675 | return (proxy_mode_ == kHTTPProxy) || establishing_tunnel_; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1676 | } |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1677 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1678 | bool HttpNetworkTransaction::ShouldApplyServerAuth() const { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1679 | return !establishing_tunnel_ && |
| 1680 | !(request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1681 | } |
| 1682 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 1683 | void HttpNetworkTransaction::AddAuthorizationHeader( |
| 1684 | HttpAuth::Target target, HttpRequestHeaders* authorization_headers) const { |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1685 | DCHECK(HaveAuth(target)); |
[email protected] | aaead50 | 2008-10-15 00:20:11 | [diff] [blame] | 1686 | |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1687 | // Add a Authorization/Proxy-Authorization header line. |
[email protected] | ac3fa8e2 | 2010-02-05 19:13:29 | [diff] [blame] | 1688 | std::string auth_token; |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1689 | int rv; |
| 1690 | if (auth_identity_[target].source == |
| 1691 | HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS) { |
| 1692 | rv = auth_handler_[target]->GenerateDefaultAuthToken( |
| 1693 | request_, &proxy_info_, &auth_token); |
| 1694 | } else { |
| 1695 | rv = auth_handler_[target]->GenerateAuthToken( |
| 1696 | auth_identity_[target].username, |
| 1697 | auth_identity_[target].password, |
| 1698 | request_, &proxy_info_, &auth_token); |
| 1699 | } |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 1700 | if (rv == OK) { |
| 1701 | authorization_headers->SetHeader( |
| 1702 | HttpAuth::GetAuthorizationHeaderName(target), auth_token); |
| 1703 | } |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1704 | |
[email protected] | ac3fa8e2 | 2010-02-05 19:13:29 | [diff] [blame] | 1705 | // TODO(cbentzel): Evict username and password from cache on non-OK return? |
| 1706 | // TODO(cbentzel): Never use this scheme again if |
| 1707 | // ERR_UNSUPPORTED_AUTH_SCHEME is returned. |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1708 | } |
| 1709 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1710 | GURL HttpNetworkTransaction::AuthOrigin(HttpAuth::Target target) const { |
| 1711 | return target == HttpAuth::AUTH_PROXY ? |
[email protected] | f6fb2de | 2009-02-19 08:11:42 | [diff] [blame] | 1712 | GURL("http://" + proxy_info_.proxy_server().host_and_port()) : |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1713 | request_->url.GetOrigin(); |
| 1714 | } |
| 1715 | |
| 1716 | std::string HttpNetworkTransaction::AuthPath(HttpAuth::Target target) |
| 1717 | const { |
| 1718 | // Proxy authentication realms apply to all paths. So we will use |
| 1719 | // empty string in place of an absolute path. |
| 1720 | return target == HttpAuth::AUTH_PROXY ? |
| 1721 | std::string() : request_->url.path(); |
| 1722 | } |
| 1723 | |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1724 | // static |
| 1725 | std::string HttpNetworkTransaction::AuthTargetString( |
| 1726 | HttpAuth::Target target) { |
| 1727 | return target == HttpAuth::AUTH_PROXY ? "proxy" : "server"; |
| 1728 | } |
| 1729 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1730 | void HttpNetworkTransaction::InvalidateRejectedAuthFromCache( |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1731 | HttpAuth::Target target, |
| 1732 | const GURL& auth_origin) { |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1733 | DCHECK(HaveAuth(target)); |
| 1734 | |
| 1735 | // TODO(eroman): this short-circuit can be relaxed. If the realm of |
| 1736 | // the preemptively used auth entry matches the realm of the subsequent |
| 1737 | // challenge, then we can invalidate the preemptively used entry. |
| 1738 | // Otherwise as-is we may send the failed credentials one extra time. |
| 1739 | if (auth_identity_[target].source == HttpAuth::IDENT_SRC_PATH_LOOKUP) |
| 1740 | return; |
| 1741 | |
| 1742 | // Clear the cache entry for the identity we just failed on. |
| 1743 | // Note: we require the username/password to match before invalidating |
| 1744 | // since the entry in the cache may be newer than what we used last time. |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1745 | session_->auth_cache()->Remove(auth_origin, |
[email protected] | 5d0153c51 | 2009-01-12 19:08:36 | [diff] [blame] | 1746 | auth_handler_[target]->realm(), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1747 | auth_identity_[target].username, |
| 1748 | auth_identity_[target].password); |
| 1749 | } |
| 1750 | |
| 1751 | bool HttpNetworkTransaction::SelectPreemptiveAuth(HttpAuth::Target target) { |
| 1752 | DCHECK(!HaveAuth(target)); |
| 1753 | |
| 1754 | // Don't do preemptive authorization if the URL contains a username/password, |
| 1755 | // since we must first be challenged in order to use the URL's identity. |
| 1756 | if (request_->url.has_username()) |
| 1757 | return false; |
| 1758 | |
| 1759 | // SelectPreemptiveAuth() is on the critical path for each request, so it |
| 1760 | // is expected to be fast. LookupByPath() is fast in the common case, since |
| 1761 | // the number of http auth cache entries is expected to be very small. |
| 1762 | // (For most users in fact, it will be 0.) |
| 1763 | |
| 1764 | HttpAuthCache::Entry* entry = session_->auth_cache()->LookupByPath( |
| 1765 | AuthOrigin(target), AuthPath(target)); |
| 1766 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1767 | // We don't support preemptive authentication for connection-based |
| 1768 | // authentication schemes because they can't reuse entry->handler(). |
| 1769 | // Hopefully we can remove this limitation in the future. |
| 1770 | if (entry && !entry->handler()->is_connection_based()) { |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1771 | auth_identity_[target].source = HttpAuth::IDENT_SRC_PATH_LOOKUP; |
| 1772 | auth_identity_[target].invalid = false; |
| 1773 | auth_identity_[target].username = entry->username(); |
| 1774 | auth_identity_[target].password = entry->password(); |
| 1775 | auth_handler_[target] = entry->handler(); |
| 1776 | return true; |
| 1777 | } |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1778 | |
| 1779 | // TODO(cbentzel): Preemptively use default credentials if they have worked |
| 1780 | // for the origin/path in the past to save a round trip. |
| 1781 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1782 | return false; |
| 1783 | } |
| 1784 | |
| 1785 | bool HttpNetworkTransaction::SelectNextAuthIdentityToTry( |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1786 | HttpAuth::Target target, |
| 1787 | const GURL& auth_origin) { |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1788 | DCHECK(auth_handler_[target]); |
| 1789 | DCHECK(auth_identity_[target].invalid); |
| 1790 | |
| 1791 | // Try to use the username/password encoded into the URL first. |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1792 | if (target == HttpAuth::AUTH_SERVER && request_->url.has_username() && |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 1793 | !embedded_identity_used_) { |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1794 | auth_identity_[target].source = HttpAuth::IDENT_SRC_URL; |
| 1795 | auth_identity_[target].invalid = false; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 1796 | // Extract the username:password from the URL. |
[email protected] | 99d6935 | 2009-09-16 00:20:29 | [diff] [blame] | 1797 | GetIdentityFromURL(request_->url, |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 1798 | &auth_identity_[target].username, |
| 1799 | &auth_identity_[target].password); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 1800 | embedded_identity_used_ = true; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1801 | // TODO(eroman): If the password is blank, should we also try combining |
| 1802 | // with a password from the cache? |
| 1803 | return true; |
| 1804 | } |
| 1805 | |
| 1806 | // Check the auth cache for a realm entry. |
| 1807 | HttpAuthCache::Entry* entry = session_->auth_cache()->LookupByRealm( |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1808 | auth_origin, auth_handler_[target]->realm()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1809 | |
| 1810 | if (entry) { |
| 1811 | // Disallow re-using of identity if the scheme of the originating challenge |
| 1812 | // does not match. This protects against the following situation: |
| 1813 | // 1. Browser prompts user to sign into DIGEST realm="Foo". |
| 1814 | // 2. Since the auth-scheme is not BASIC, the user is reasured that it |
| 1815 | // will not be sent over the wire in clear text. So they use their |
| 1816 | // most trusted password. |
| 1817 | // 3. Next, the browser receives a challenge for BASIC realm="Foo". This |
| 1818 | // is the same realm that we have a cached identity for. However if |
| 1819 | // we use that identity, it would get sent over the wire in |
| 1820 | // clear text (which isn't what the user agreed to when entering it). |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1821 | if (entry->handler()->scheme() == auth_handler_[target]->scheme()) { |
| 1822 | auth_identity_[target].source = HttpAuth::IDENT_SRC_REALM_LOOKUP; |
| 1823 | auth_identity_[target].invalid = false; |
| 1824 | auth_identity_[target].username = entry->username(); |
| 1825 | auth_identity_[target].password = entry->password(); |
| 1826 | return true; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1827 | } |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1828 | LOG(WARNING) << "The scheme of realm " << auth_handler_[target]->realm() |
| 1829 | << " has changed from " << entry->handler()->scheme() |
| 1830 | << " to " << auth_handler_[target]->scheme(); |
| 1831 | // Fall through. |
| 1832 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1833 | |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1834 | // Use default credentials (single sign on) if this is the first attempt |
| 1835 | // at identity. Do not allow multiple times as it will infinite loop. |
| 1836 | // We use default credentials after checking the auth cache so that if |
| 1837 | // single sign-on doesn't work, we won't try default credentials for future |
| 1838 | // transactions. |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 1839 | if (!default_credentials_used_ && |
| 1840 | auth_handler_[target]->AllowsDefaultCredentials()) { |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1841 | auth_identity_[target].source = HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1842 | auth_identity_[target].invalid = false; |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1843 | default_credentials_used_ = true; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1844 | return true; |
| 1845 | } |
[email protected] | d7f1663 | 2010-03-29 18:02:36 | [diff] [blame] | 1846 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1847 | return false; |
| 1848 | } |
| 1849 | |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1850 | std::string HttpNetworkTransaction::AuthChallengeLogMessage() const { |
| 1851 | std::string msg; |
| 1852 | std::string header_val; |
| 1853 | void* iter = NULL; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1854 | scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
| 1855 | while (headers->EnumerateHeader(&iter, "proxy-authenticate", &header_val)) { |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1856 | msg.append("\n Has header Proxy-Authenticate: "); |
| 1857 | msg.append(header_val); |
| 1858 | } |
| 1859 | |
| 1860 | iter = NULL; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1861 | while (headers->EnumerateHeader(&iter, "www-authenticate", &header_val)) { |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1862 | msg.append("\n Has header WWW-Authenticate: "); |
| 1863 | msg.append(header_val); |
| 1864 | } |
| 1865 | |
| 1866 | // RFC 4559 requires that a proxy indicate its support of NTLM/Negotiate |
| 1867 | // authentication with a "Proxy-Support: Session-Based-Authentication" |
| 1868 | // response header. |
| 1869 | iter = NULL; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1870 | while (headers->EnumerateHeader(&iter, "proxy-support", &header_val)) { |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1871 | msg.append("\n Has header Proxy-Support: "); |
| 1872 | msg.append(header_val); |
| 1873 | } |
| 1874 | |
| 1875 | return msg; |
| 1876 | } |
| 1877 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1878 | int HttpNetworkTransaction::HandleAuthChallenge() { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1879 | scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
| 1880 | DCHECK(headers); |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1881 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1882 | int status = headers->response_code(); |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1883 | if (status != 401 && status != 407) |
| 1884 | return OK; |
| 1885 | HttpAuth::Target target = status == 407 ? |
| 1886 | HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER; |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1887 | GURL auth_origin = AuthOrigin(target); |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1888 | |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1889 | LOG(INFO) << "The " << AuthTargetString(target) << " " |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1890 | << auth_origin << " requested auth" |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1891 | << AuthChallengeLogMessage(); |
| 1892 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1893 | if (target == HttpAuth::AUTH_PROXY && proxy_info_.is_direct()) |
| 1894 | return ERR_UNEXPECTED_PROXY_AUTH; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1895 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1896 | // The auth we tried just failed, hence it can't be valid. Remove it from |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 1897 | // the cache so it won't be used again. |
| 1898 | // TODO(wtc): IsFinalRound is not the right condition. In a multi-round |
| 1899 | // auth sequence, the server may fail the auth in round 1 if our first |
| 1900 | // authorization header is broken. We should inspect response_.headers to |
| 1901 | // determine if the server already failed the auth or wants us to continue. |
| 1902 | // See http://crbug.com/21015. |
| 1903 | if (HaveAuth(target) && auth_handler_[target]->IsFinalRound()) { |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1904 | InvalidateRejectedAuthFromCache(target, auth_origin); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 1905 | auth_handler_[target] = NULL; |
| 1906 | auth_identity_[target] = HttpAuth::Identity(); |
| 1907 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1908 | |
| 1909 | auth_identity_[target].invalid = true; |
| 1910 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1911 | if (target != HttpAuth::AUTH_SERVER || |
| 1912 | !(request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA)) { |
| 1913 | // Find the best authentication challenge that we support. |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 1914 | HttpAuth::ChooseBestChallenge(session_->http_auth_handler_factory(), |
| 1915 | headers, target, |
| 1916 | auth_origin, &auth_handler_[target]); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1917 | } |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1918 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1919 | if (!auth_handler_[target]) { |
| 1920 | if (establishing_tunnel_) { |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1921 | LOG(ERROR) << "Can't perform auth to the " << AuthTargetString(target) |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1922 | << " " << auth_origin << " when establishing a tunnel" |
[email protected] | 3c86adc6 | 2009-04-21 16:48:21 | [diff] [blame] | 1923 | << AuthChallengeLogMessage(); |
[email protected] | 655bdba | 2009-03-13 23:35:38 | [diff] [blame] | 1924 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1925 | // We are establishing a tunnel, we can't show the error page because an |
| 1926 | // active network attacker could control its contents. Instead, we just |
| 1927 | // fail to establish the tunnel. |
[email protected] | 9f9f86c | 2009-03-12 22:32:42 | [diff] [blame] | 1928 | DCHECK(target == HttpAuth::AUTH_PROXY); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1929 | return ERR_PROXY_AUTH_REQUESTED; |
| 1930 | } |
| 1931 | // We found no supported challenge -- let the transaction continue |
| 1932 | // so we end up displaying the error page. |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1933 | return OK; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 1934 | } |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1935 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1936 | if (auth_handler_[target]->NeedsIdentity()) { |
| 1937 | // Pick a new auth identity to try, by looking to the URL and auth cache. |
| 1938 | // If an identity to try is found, it is saved to auth_identity_[target]. |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1939 | SelectNextAuthIdentityToTry(target, auth_origin); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1940 | } else { |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 1941 | // Proceed with the existing identity or a null identity. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1942 | // |
| 1943 | // TODO(wtc): Add a safeguard against infinite transaction restarts, if |
| 1944 | // the server keeps returning "NTLM". |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 1945 | auth_identity_[target].invalid = false; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1946 | } |
| 1947 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1948 | // Make a note that we are waiting for auth. This variable is inspected |
| 1949 | // when the client calls RestartWithAuth() to pick up where we left off. |
| 1950 | pending_auth_target_ = target; |
| 1951 | |
| 1952 | if (auth_identity_[target].invalid) { |
| 1953 | // We have exhausted all identity possibilities, all we can do now is |
| 1954 | // pass the challenge information back to the client. |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1955 | PopulateAuthChallenge(target, auth_origin); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 1956 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 1957 | |
| 1958 | // SPN determination (for Negotiate) requires a DNS lookup to find the |
| 1959 | // canonical name. This needs to be done asynchronously to prevent blocking |
| 1960 | // the IO thread. |
| 1961 | if (auth_handler_[target]->NeedsCanonicalName()) |
| 1962 | next_state_ = STATE_RESOLVE_CANONICAL_NAME; |
| 1963 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1964 | return OK; |
| 1965 | } |
| 1966 | |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1967 | void HttpNetworkTransaction::PopulateAuthChallenge(HttpAuth::Target target, |
| 1968 | const GURL& auth_origin) { |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1969 | // Populates response_.auth_challenge with the authentication challenge info. |
| 1970 | // This info is consumed by URLRequestHttpJob::GetAuthChallengeInfo(). |
| 1971 | |
| 1972 | AuthChallengeInfo* auth_info = new AuthChallengeInfo; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1973 | auth_info->is_proxy = target == HttpAuth::AUTH_PROXY; |
[email protected] | f494fae | 2009-10-15 17:00:47 | [diff] [blame] | 1974 | auth_info->host_and_port = ASCIIToWide(GetHostAndPort(auth_origin)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1975 | auth_info->scheme = ASCIIToWide(auth_handler_[target]->scheme()); |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1976 | // TODO(eroman): decode realm according to RFC 2047. |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1977 | auth_info->realm = ASCIIToWide(auth_handler_[target]->realm()); |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 1978 | response_.auth_challenge = auth_info; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1979 | } |
| 1980 | |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 1981 | void HttpNetworkTransaction::MarkBrokenAlternateProtocolAndFallback() { |
| 1982 | HostPortPair http_host_port_pair; |
| 1983 | http_host_port_pair.host = request_->url.host(); |
| 1984 | http_host_port_pair.port = request_->url.EffectiveIntPort(); |
| 1985 | |
| 1986 | session_->mutable_alternate_protocols()->MarkBrokenAlternateProtocolFor( |
| 1987 | http_host_port_pair); |
| 1988 | |
| 1989 | alternate_protocol_mode_ = kDoNotUseAlternateProtocol; |
| 1990 | if (connection_->socket()) |
| 1991 | connection_->socket()->Disconnect(); |
| 1992 | connection_->Reset(); |
| 1993 | next_state_ = STATE_INIT_CONNECTION; |
| 1994 | } |
| 1995 | |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 1996 | } // namespace net |