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