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