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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( |
|
Ryan Hamilton
2015/02/27 18:20:48
As discussed yesterday, I think this needs to retu
Bence
2015/02/27 19:31:41
Absolutely. Now even after this CL we can only ha
| |
| 175 const GURL& original_url, | 175 const GURL& original_url, |
| 176 GURL* alternate_url) { | 176 GURL* alternate_url) { |
| 177 const AlternateProtocolInfo kNoAlternateProtocol; | 177 const AlternateProtocolInfo kNoAlternateProtocol; |
| 178 | 178 |
| 179 if (!session_->params().use_alternate_protocols) | 179 if (!session_->params().use_alternate_protocols) |
| 180 return kNoAlternateProtocol; | 180 return kNoAlternateProtocol; |
| 181 | 181 |
| 182 if (original_url.SchemeIs("ftp")) | 182 if (original_url.SchemeIs("ftp")) |
| 183 return kNoAlternateProtocol; | 183 return kNoAlternateProtocol; |
| 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 AlternateProtocols alternate_protocols = |
| 189 http_server_properties.GetAlternateProtocol(origin); | 189 http_server_properties.GetAlternateProtocols(origin); |
| 190 if (alternate_protocols.empty()) | |
| 191 return kNoAlternateProtocol; | |
| 192 for (AlternateProtocols::iterator alternate = alternate_protocols.begin(); | |
| 193 alternate != alternate_protocols.end(); ++alternate) { | |
|
Ryan Hamilton
2015/02/27 18:20:48
Can you use a C++ range based for loop here?
Bence
2015/02/27 19:31:41
Done.
| |
| 194 if (alternate->is_broken) { | |
| 195 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | |
| 196 continue; | |
| 197 } | |
| 190 | 198 |
| 191 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 199 // Some shared unix systems may have user home directories (like |
| 192 return kNoAlternateProtocol; | 200 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
| 193 if (alternate.is_broken) { | 201 // idea already, but with Alternate-Protocol, it provides the ability for a |
| 194 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | 202 // single user on a multi-user system to hijack the alternate protocol. |
| 195 return kNoAlternateProtocol; | 203 // These systems also enforce ports <1024 as restricted ports. So don't |
| 204 // allow protocol upgrades to user-controllable ports. | |
| 205 const int kUnrestrictedPort = 1024; | |
| 206 if (!session_->params().enable_user_alternate_protocol_ports && | |
| 207 (alternate->port >= kUnrestrictedPort && | |
| 208 origin.port() < kUnrestrictedPort)) | |
| 209 continue; | |
| 210 | |
| 211 origin.set_port(alternate->port); | |
| 212 if (alternate->protocol >= NPN_SPDY_MINIMUM_VERSION && | |
| 213 alternate->protocol <= NPN_SPDY_MAXIMUM_VERSION) { | |
| 214 if (!HttpStreamFactory::spdy_enabled()) | |
| 215 continue; | |
| 216 | |
| 217 if (session_->HasSpdyExclusion(origin)) | |
| 218 continue; | |
| 219 | |
| 220 *alternate_url = UpgradeUrlToHttps(original_url, alternate->port); | |
| 221 return *alternate; | |
| 222 } else { | |
| 223 DCHECK_EQ(QUIC, alternate->protocol); | |
| 224 if (!session_->params().enable_quic) | |
| 225 continue; | |
| 226 | |
| 227 // TODO(rch): Figure out how to make QUIC iteract with PAC | |
| 228 // scripts. By not re-writing the URL, we will query the PAC script | |
| 229 // for the proxy to use to reach the original URL via TCP. But | |
| 230 // the alternate request will be going via UDP to a different port. | |
| 231 *alternate_url = original_url; | |
| 232 return *alternate; | |
| 233 } | |
| 196 } | 234 } |
| 197 if (!IsAlternateProtocolValid(alternate.protocol)) { | 235 return kNoAlternateProtocol; |
| 198 NOTREACHED(); | |
| 199 return kNoAlternateProtocol; | |
| 200 } | |
| 201 | |
| 202 // Some shared unix systems may have user home directories (like | |
| 203 // http://foo.com/~mike) which allow users to emit headers. This is a bad | |
| 204 // idea already, but with Alternate-Protocol, it provides the ability for a | |
| 205 // single user on a multi-user system to hijack the alternate protocol. | |
| 206 // These systems also enforce ports <1024 as restricted ports. So don't | |
| 207 // allow protocol upgrades to user-controllable ports. | |
| 208 const int kUnrestrictedPort = 1024; | |
| 209 if (!session_->params().enable_user_alternate_protocol_ports && | |
| 210 (alternate.port >= kUnrestrictedPort && | |
| 211 origin.port() < kUnrestrictedPort)) | |
| 212 return kNoAlternateProtocol; | |
| 213 | |
| 214 origin.set_port(alternate.port); | |
| 215 if (alternate.protocol >= NPN_SPDY_MINIMUM_VERSION && | |
| 216 alternate.protocol <= NPN_SPDY_MAXIMUM_VERSION) { | |
| 217 if (!HttpStreamFactory::spdy_enabled()) | |
| 218 return kNoAlternateProtocol; | |
| 219 | |
| 220 if (session_->HasSpdyExclusion(origin)) | |
| 221 return kNoAlternateProtocol; | |
| 222 | |
| 223 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); | |
| 224 } else { | |
| 225 DCHECK_EQ(QUIC, alternate.protocol); | |
| 226 if (!session_->params().enable_quic) | |
| 227 return kNoAlternateProtocol; | |
| 228 | |
| 229 // TODO(rch): Figure out how to make QUIC iteract with PAC | |
| 230 // scripts. By not re-writing the URL, we will query the PAC script | |
| 231 // for the proxy to use to reach the original URL via TCP. But | |
| 232 // the alternate request will be going via UDP to a different port. | |
| 233 *alternate_url = original_url; | |
| 234 } | |
| 235 return alternate; | |
| 236 } | 236 } |
| 237 | 237 |
| 238 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { | 238 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { |
| 239 DCHECK(ContainsKey(request_map_, job)); | 239 DCHECK(ContainsKey(request_map_, job)); |
| 240 DCHECK_EQ(request_map_[job], request); | 240 DCHECK_EQ(request_map_[job], request); |
| 241 DCHECK(!ContainsKey(orphaned_job_set_, job)); | 241 DCHECK(!ContainsKey(orphaned_job_set_, job)); |
| 242 | 242 |
| 243 request_map_.erase(job); | 243 request_map_.erase(job); |
| 244 | 244 |
| 245 orphaned_job_set_.insert(job); | 245 orphaned_job_set_.insert(job); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 delete job; | 294 delete job; |
| 295 } | 295 } |
| 296 | 296 |
| 297 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 297 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
| 298 preconnect_job_set_.erase(job); | 298 preconnect_job_set_.erase(job); |
| 299 delete job; | 299 delete job; |
| 300 OnPreconnectsCompleteInternal(); | 300 OnPreconnectsCompleteInternal(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 } // namespace net | 303 } // namespace net |
| OLD | NEW |