| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return kNoAlternateProtocol; | 185 return kNoAlternateProtocol; |
| 186 | 186 |
| 187 HostPortPair origin = HostPortPair(original_url.HostNoBrackets(), | 187 HostPortPair origin = HostPortPair(original_url.HostNoBrackets(), |
| 188 original_url.EffectiveIntPort()); | 188 original_url.EffectiveIntPort()); |
| 189 | 189 |
| 190 HttpServerProperties& http_server_properties = | 190 HttpServerProperties& http_server_properties = |
| 191 *session_->http_server_properties(); | 191 *session_->http_server_properties(); |
| 192 if (!http_server_properties.HasAlternateProtocol(origin)) | 192 if (!http_server_properties.HasAlternateProtocol(origin)) |
| 193 return kNoAlternateProtocol; | 193 return kNoAlternateProtocol; |
| 194 | 194 |
| 195 AlternateProtocolInfo alternate = | 195 AlternateProtocols alternate_protocols = |
| 196 http_server_properties.GetAlternateProtocol(origin); | 196 http_server_properties.GetAlternateProtocol(origin); |
| 197 if (alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) { | 197 for (AlternateProtocols::iterator alternate = alternate_protocols.begin(); |
| 198 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | 198 alternate != alternate_protocols.end(); |
| 199 return kNoAlternateProtocol; | 199 ++alternate) { |
| 200 if (alternate->protocol == ALTERNATE_PROTOCOL_BROKEN) { |
| 201 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); |
| 202 continue; |
| 203 } |
| 204 |
| 205 if (!IsAlternateProtocolValid(alternate->protocol)) { |
| 206 NOTREACHED(); |
| 207 continue; |
| 208 } |
| 209 |
| 210 // Some shared unix systems may have user home directories (like |
| 211 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
| 212 // idea already, but with Alternate-Protocol, it provides the ability for a |
| 213 // single user on a multi-user system to hijack the alternate protocol. |
| 214 // These systems also enforce ports <1024 as restricted ports. So don't |
| 215 // allow protocol upgrades to user-controllable ports. |
| 216 const int kUnrestrictedPort = 1024; |
| 217 if (!session_->params().enable_user_alternate_protocol_ports && |
| 218 (alternate->port >= kUnrestrictedPort && |
| 219 origin.port() < kUnrestrictedPort)) |
| 220 continue; |
| 221 |
| 222 origin.set_port(alternate->port); |
| 223 if (alternate->protocol >= NPN_SPDY_MINIMUM_VERSION && |
| 224 alternate->protocol <= NPN_SPDY_MAXIMUM_VERSION) { |
| 225 if (!HttpStreamFactory::spdy_enabled()) |
| 226 continue; |
| 227 |
| 228 if (session_->HasSpdyExclusion(origin)) |
| 229 continue; |
| 230 |
| 231 *alternate_url = UpgradeUrlToHttps(original_url, alternate->port); |
| 232 return *alternate; |
| 233 } else { |
| 234 DCHECK_EQ(QUIC, alternate->protocol); |
| 235 if (!session_->params().enable_quic) |
| 236 continue; |
| 237 |
| 238 // TODO(rch): Figure out how to make QUIC iteract with PAC |
| 239 // scripts. By not re-writing the URL, we will query the PAC script |
| 240 // for the proxy to use to reach the original URL via TCP. But |
| 241 // the alternate request will be going via UDP to a different port. |
| 242 *alternate_url = original_url; |
| 243 return *alternate; |
| 244 } |
| 200 } | 245 } |
| 201 | 246 return kNoAlternateProtocol; |
| 202 if (!IsAlternateProtocolValid(alternate.protocol)) { | |
| 203 NOTREACHED(); | |
| 204 return kNoAlternateProtocol; | |
| 205 } | |
| 206 | |
| 207 // Some shared unix systems may have user home directories (like | |
| 208 // http://foo.com/~mike) which allow users to emit headers. This is a bad | |
| 209 // idea already, but with Alternate-Protocol, it provides the ability for a | |
| 210 // single user on a multi-user system to hijack the alternate protocol. | |
| 211 // These systems also enforce ports <1024 as restricted ports. So don't | |
| 212 // allow protocol upgrades to user-controllable ports. | |
| 213 const int kUnrestrictedPort = 1024; | |
| 214 if (!session_->params().enable_user_alternate_protocol_ports && | |
| 215 (alternate.port >= kUnrestrictedPort && | |
| 216 origin.port() < kUnrestrictedPort)) | |
| 217 return kNoAlternateProtocol; | |
| 218 | |
| 219 origin.set_port(alternate.port); | |
| 220 if (alternate.protocol >= NPN_SPDY_MINIMUM_VERSION && | |
| 221 alternate.protocol <= NPN_SPDY_MAXIMUM_VERSION) { | |
| 222 if (!HttpStreamFactory::spdy_enabled()) | |
| 223 return kNoAlternateProtocol; | |
| 224 | |
| 225 if (session_->HasSpdyExclusion(origin)) | |
| 226 return kNoAlternateProtocol; | |
| 227 | |
| 228 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); | |
| 229 } else { | |
| 230 DCHECK_EQ(QUIC, alternate.protocol); | |
| 231 if (!session_->params().enable_quic) | |
| 232 return kNoAlternateProtocol; | |
| 233 | |
| 234 // TODO(rch): Figure out how to make QUIC iteract with PAC | |
| 235 // scripts. By not re-writing the URL, we will query the PAC script | |
| 236 // for the proxy to use to reach the original URL via TCP. But | |
| 237 // the alternate request will be going via UDP to a different port. | |
| 238 *alternate_url = original_url; | |
| 239 } | |
| 240 return alternate; | |
| 241 } | 247 } |
| 242 | 248 |
| 243 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { | 249 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { |
| 244 DCHECK(ContainsKey(request_map_, job)); | 250 DCHECK(ContainsKey(request_map_, job)); |
| 245 DCHECK_EQ(request_map_[job], request); | 251 DCHECK_EQ(request_map_[job], request); |
| 246 DCHECK(!ContainsKey(orphaned_job_set_, job)); | 252 DCHECK(!ContainsKey(orphaned_job_set_, job)); |
| 247 | 253 |
| 248 request_map_.erase(job); | 254 request_map_.erase(job); |
| 249 | 255 |
| 250 orphaned_job_set_.insert(job); | 256 orphaned_job_set_.insert(job); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 delete job; | 305 delete job; |
| 300 } | 306 } |
| 301 | 307 |
| 302 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 308 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
| 303 preconnect_job_set_.erase(job); | 309 preconnect_job_set_.erase(job); |
| 304 delete job; | 310 delete job; |
| 305 OnPreconnectsCompleteInternal(); | 311 OnPreconnectsCompleteInternal(); |
| 306 } | 312 } |
| 307 | 313 |
| 308 } // namespace net | 314 } // namespace net |
| OLD | NEW |