Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_stream_factory_impl.h" | 5 #include "net/http/http_stream_factory_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 HttpStreamRequest::Delegate* delegate, | 98 HttpStreamRequest::Delegate* delegate, |
| 99 WebSocketHandshakeStreamBase::CreateHelper* | 99 WebSocketHandshakeStreamBase::CreateHelper* |
| 100 websocket_handshake_stream_create_helper, | 100 websocket_handshake_stream_create_helper, |
| 101 const BoundNetLog& net_log) { | 101 const BoundNetLog& net_log) { |
| 102 Request* request = new Request(request_info.url, | 102 Request* request = new Request(request_info.url, |
| 103 this, | 103 this, |
| 104 delegate, | 104 delegate, |
| 105 websocket_handshake_stream_create_helper, | 105 websocket_handshake_stream_create_helper, |
| 106 net_log); | 106 net_log); |
| 107 | 107 |
| 108 GURL alternate_url; | 108 GURL alternate_url; |
|
Ryan Hamilton
2015/03/17 13:53:09
nit: At some point we really should get rid of thi
Bence
2015/03/17 14:40:52
Done.
| |
| 109 AlternateProtocolInfo alternate = | 109 AlternativeService alternative_service = |
| 110 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 110 GetAlternativeServiceRequestFor(request_info.url, &alternate_url); |
| 111 Job* alternate_job = NULL; | 111 Job* alternate_job = NULL; |
| 112 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 112 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 113 // Never share connection with other jobs for FTP requests. | 113 // Never share connection with other jobs for FTP requests. |
| 114 DCHECK(!request_info.url.SchemeIs("ftp")); | 114 DCHECK(!request_info.url.SchemeIs("ftp")); |
| 115 | 115 |
| 116 HttpRequestInfo alternate_request_info = request_info; | 116 HttpRequestInfo alternate_request_info = request_info; |
| 117 alternate_request_info.url = alternate_url; | 117 alternate_request_info.url = alternate_url; |
| 118 alternate_job = | 118 alternate_job = |
| 119 new Job(this, session_, alternate_request_info, priority, | 119 new Job(this, session_, alternate_request_info, priority, |
| 120 server_ssl_config, proxy_ssl_config, net_log.net_log()); | 120 server_ssl_config, proxy_ssl_config, net_log.net_log()); |
| 121 request->AttachJob(alternate_job); | 121 request->AttachJob(alternate_job); |
| 122 alternate_job->MarkAsAlternate(request_info.url, alternate); | 122 alternate_job->MarkAsAlternate(request_info.url, alternative_service); |
| 123 } | 123 } |
| 124 | 124 |
| 125 Job* job = new Job(this, session_, request_info, priority, | 125 Job* job = new Job(this, session_, request_info, priority, |
| 126 server_ssl_config, proxy_ssl_config, net_log.net_log()); | 126 server_ssl_config, proxy_ssl_config, net_log.net_log()); |
| 127 request->AttachJob(job); | 127 request->AttachJob(job); |
| 128 if (alternate_job) { | 128 if (alternate_job) { |
| 129 // Never share connection with other jobs for FTP requests. | 129 // Never share connection with other jobs for FTP requests. |
| 130 DCHECK(!request_info.url.SchemeIs("ftp")); | 130 DCHECK(!request_info.url.SchemeIs("ftp")); |
| 131 | 131 |
| 132 job->WaitFor(alternate_job); | 132 job->WaitFor(alternate_job); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 143 } | 143 } |
| 144 | 144 |
| 145 void HttpStreamFactoryImpl::PreconnectStreams( | 145 void HttpStreamFactoryImpl::PreconnectStreams( |
| 146 int num_streams, | 146 int num_streams, |
| 147 const HttpRequestInfo& request_info, | 147 const HttpRequestInfo& request_info, |
| 148 RequestPriority priority, | 148 RequestPriority priority, |
| 149 const SSLConfig& server_ssl_config, | 149 const SSLConfig& server_ssl_config, |
| 150 const SSLConfig& proxy_ssl_config) { | 150 const SSLConfig& proxy_ssl_config) { |
| 151 DCHECK(!for_websockets_); | 151 DCHECK(!for_websockets_); |
| 152 GURL alternate_url; | 152 GURL alternate_url; |
| 153 AlternateProtocolInfo alternate = | 153 AlternativeService alternative_service = |
| 154 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 154 GetAlternativeServiceRequestFor(request_info.url, &alternate_url); |
| 155 Job* job = NULL; | 155 Job* job = NULL; |
| 156 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 156 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 157 HttpRequestInfo alternate_request_info = request_info; | 157 HttpRequestInfo alternate_request_info = request_info; |
| 158 alternate_request_info.url = alternate_url; | 158 alternate_request_info.url = alternate_url; |
| 159 job = new Job(this, session_, alternate_request_info, priority, | 159 job = new Job(this, session_, alternate_request_info, priority, |
| 160 server_ssl_config, proxy_ssl_config, session_->net_log()); | 160 server_ssl_config, proxy_ssl_config, session_->net_log()); |
| 161 job->MarkAsAlternate(request_info.url, alternate); | 161 job->MarkAsAlternate(request_info.url, alternative_service); |
| 162 } else { | 162 } else { |
| 163 job = new Job(this, session_, request_info, priority, | 163 job = new Job(this, session_, request_info, priority, |
| 164 server_ssl_config, proxy_ssl_config, session_->net_log()); | 164 server_ssl_config, proxy_ssl_config, session_->net_log()); |
| 165 } | 165 } |
| 166 preconnect_job_set_.insert(job); | 166 preconnect_job_set_.insert(job); |
| 167 job->Preconnect(num_streams); | 167 job->Preconnect(num_streams); |
| 168 } | 168 } |
| 169 | 169 |
| 170 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { | 170 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
| 171 return session_->params().host_mapping_rules; | 171 return session_->params().host_mapping_rules; |
| 172 } | 172 } |
| 173 | 173 |
| 174 AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( | 174 AlternativeService HttpStreamFactoryImpl::GetAlternativeServiceRequestFor( |
| 175 const GURL& original_url, | 175 const GURL& original_url, |
| 176 GURL* alternate_url) { | 176 GURL* alternate_url) { |
| 177 const AlternateProtocolInfo kNoAlternateProtocol; | 177 const AlternativeService kNoAlternativeService; |
| 178 | 178 |
| 179 if (!session_->params().use_alternate_protocols) | 179 if (!session_->params().use_alternate_protocols) |
| 180 return kNoAlternateProtocol; | 180 return kNoAlternativeService; |
| 181 | 181 |
| 182 if (original_url.SchemeIs("ftp")) | 182 if (original_url.SchemeIs("ftp")) |
| 183 return kNoAlternateProtocol; | 183 return kNoAlternativeService; |
| 184 | 184 |
| 185 HostPortPair origin = HostPortPair::FromURL(original_url); | 185 HostPortPair origin = HostPortPair::FromURL(original_url); |
| 186 HttpServerProperties& http_server_properties = | 186 HttpServerProperties& http_server_properties = |
| 187 *session_->http_server_properties(); | 187 *session_->http_server_properties(); |
| 188 const AlternateProtocolInfo alternate = | 188 const AlternateProtocolInfo alternate = |
| 189 http_server_properties.GetAlternateProtocol(origin); | 189 http_server_properties.GetAlternateProtocol(origin); |
| 190 | 190 |
| 191 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 191 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 192 return kNoAlternateProtocol; | 192 return kNoAlternativeService; |
| 193 const AlternativeService alternative_service(alternate.protocol, | 193 const AlternativeService alternative_service(alternate.protocol, |
| 194 origin.host(), alternate.port); | 194 origin.host(), alternate.port); |
| 195 if (http_server_properties.IsAlternativeServiceBroken(alternative_service)) { | 195 if (http_server_properties.IsAlternativeServiceBroken(alternative_service)) { |
| 196 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | 196 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); |
| 197 return kNoAlternateProtocol; | 197 return kNoAlternativeService; |
| 198 } | 198 } |
| 199 if (!IsAlternateProtocolValid(alternate.protocol)) { | 199 if (!IsAlternateProtocolValid(alternate.protocol)) { |
| 200 NOTREACHED(); | 200 NOTREACHED(); |
| 201 return kNoAlternateProtocol; | 201 return kNoAlternativeService; |
| 202 } | 202 } |
| 203 | 203 |
| 204 // Some shared unix systems may have user home directories (like | 204 // Some shared unix systems may have user home directories (like |
| 205 // http://foo.com/~mike) which allow users to emit headers. This is a bad | 205 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
| 206 // idea already, but with Alternate-Protocol, it provides the ability for a | 206 // idea already, but with Alternate-Protocol, it provides the ability for a |
| 207 // single user on a multi-user system to hijack the alternate protocol. | 207 // single user on a multi-user system to hijack the alternate protocol. |
| 208 // These systems also enforce ports <1024 as restricted ports. So don't | 208 // These systems also enforce ports <1024 as restricted ports. So don't |
| 209 // allow protocol upgrades to user-controllable ports. | 209 // allow protocol upgrades to user-controllable ports. |
| 210 const int kUnrestrictedPort = 1024; | 210 const int kUnrestrictedPort = 1024; |
| 211 if (!session_->params().enable_user_alternate_protocol_ports && | 211 if (!session_->params().enable_user_alternate_protocol_ports && |
| 212 (alternate.port >= kUnrestrictedPort && | 212 (alternate.port >= kUnrestrictedPort && |
| 213 origin.port() < kUnrestrictedPort)) | 213 origin.port() < kUnrestrictedPort)) |
| 214 return kNoAlternateProtocol; | 214 return kNoAlternativeService; |
| 215 | 215 |
| 216 origin.set_port(alternate.port); | 216 origin.set_port(alternate.port); |
| 217 if (alternate.protocol >= NPN_SPDY_MINIMUM_VERSION && | 217 if (alternate.protocol >= NPN_SPDY_MINIMUM_VERSION && |
| 218 alternate.protocol <= NPN_SPDY_MAXIMUM_VERSION) { | 218 alternate.protocol <= NPN_SPDY_MAXIMUM_VERSION) { |
| 219 if (!HttpStreamFactory::spdy_enabled()) | 219 if (!HttpStreamFactory::spdy_enabled()) |
| 220 return kNoAlternateProtocol; | 220 return kNoAlternativeService; |
| 221 | 221 |
| 222 if (session_->HasSpdyExclusion(origin)) | 222 if (session_->HasSpdyExclusion(origin)) |
| 223 return kNoAlternateProtocol; | 223 return kNoAlternativeService; |
| 224 | 224 |
| 225 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); | 225 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); |
| 226 } else { | 226 } else { |
| 227 DCHECK_EQ(QUIC, alternate.protocol); | 227 DCHECK_EQ(QUIC, alternate.protocol); |
| 228 if (!session_->params().enable_quic) | 228 if (!session_->params().enable_quic) |
| 229 return kNoAlternateProtocol; | 229 return kNoAlternativeService; |
| 230 | 230 |
| 231 // TODO(rch): Figure out how to make QUIC iteract with PAC | 231 // TODO(rch): Figure out how to make QUIC iteract with PAC |
| 232 // scripts. By not re-writing the URL, we will query the PAC script | 232 // scripts. By not re-writing the URL, we will query the PAC script |
| 233 // for the proxy to use to reach the original URL via TCP. But | 233 // for the proxy to use to reach the original URL via TCP. But |
| 234 // the alternate request will be going via UDP to a different port. | 234 // the alternate request will be going via UDP to a different port. |
| 235 *alternate_url = original_url; | 235 *alternate_url = original_url; |
| 236 } | 236 } |
| 237 return alternate; | 237 return AlternativeService(alternate.protocol, origin.host(), alternate.port); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { | 240 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { |
| 241 DCHECK(ContainsKey(request_map_, job)); | 241 DCHECK(ContainsKey(request_map_, job)); |
| 242 DCHECK_EQ(request_map_[job], request); | 242 DCHECK_EQ(request_map_[job], request); |
| 243 DCHECK(!ContainsKey(orphaned_job_set_, job)); | 243 DCHECK(!ContainsKey(orphaned_job_set_, job)); |
| 244 | 244 |
| 245 request_map_.erase(job); | 245 request_map_.erase(job); |
| 246 | 246 |
| 247 orphaned_job_set_.insert(job); | 247 orphaned_job_set_.insert(job); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 delete job; | 296 delete job; |
| 297 } | 297 } |
| 298 | 298 |
| 299 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 299 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
| 300 preconnect_job_set_.erase(job); | 300 preconnect_job_set_.erase(job); |
| 301 delete job; | 301 delete job; |
| 302 OnPreconnectsCompleteInternal(); | 302 OnPreconnectsCompleteInternal(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 } // namespace net | 305 } // namespace net |
| OLD | NEW |