| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 preconnect_job_set_.insert(job); | 145 preconnect_job_set_.insert(job); |
| 146 job->Preconnect(num_streams); | 146 job->Preconnect(num_streams); |
| 147 } | 147 } |
| 148 | 148 |
| 149 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { | 149 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
| 150 return session_->params().host_mapping_rules; | 150 return session_->params().host_mapping_rules; |
| 151 } | 151 } |
| 152 | 152 |
| 153 AlternativeServiceVector HttpStreamFactoryImpl::GetAlternativeServicesFor( | 153 AlternativeServiceVector HttpStreamFactoryImpl::GetAlternativeServicesFor( |
| 154 const GURL& original_url) { | 154 const GURL& original_url) { |
| 155 if (!session_->params().use_alternative_services) | |
| 156 return AlternativeServiceVector(); | |
| 157 | |
| 158 if (original_url.SchemeIs("ftp")) | 155 if (original_url.SchemeIs("ftp")) |
| 159 return AlternativeServiceVector(); | 156 return AlternativeServiceVector(); |
| 160 | 157 |
| 161 HostPortPair origin = HostPortPair::FromURL(original_url); | 158 HostPortPair origin = HostPortPair::FromURL(original_url); |
| 162 HttpServerProperties& http_server_properties = | 159 HttpServerProperties& http_server_properties = |
| 163 *session_->http_server_properties(); | 160 *session_->http_server_properties(); |
| 164 const AlternativeServiceVector alternative_service_vector = | 161 const AlternativeServiceVector alternative_service_vector = |
| 165 http_server_properties.GetAlternativeServices(origin); | 162 http_server_properties.GetAlternativeServices(origin); |
| 166 if (alternative_service_vector.empty()) | 163 if (alternative_service_vector.empty()) |
| 167 return AlternativeServiceVector(); | 164 return AlternativeServiceVector(); |
| 168 | 165 |
| 166 const bool enable_different_host = |
| 167 session_->params().use_alternative_services; |
| 168 |
| 169 AlternativeServiceVector enabled_alternative_service_vector; | 169 AlternativeServiceVector enabled_alternative_service_vector; |
| 170 for (const AlternativeService& alternative_service : | 170 for (const AlternativeService& alternative_service : |
| 171 alternative_service_vector) { | 171 alternative_service_vector) { |
| 172 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); | 172 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); |
| 173 if (http_server_properties.IsAlternativeServiceBroken( | 173 if (http_server_properties.IsAlternativeServiceBroken( |
| 174 alternative_service)) { | 174 alternative_service)) { |
| 175 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | 175 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); |
| 176 continue; | 176 continue; |
| 177 } | 177 } |
| 178 | 178 |
| 179 if (origin.host() != alternative_service.host && !enable_different_host) |
| 180 continue; |
| 181 |
| 179 // Some shared unix systems may have user home directories (like | 182 // Some shared unix systems may have user home directories (like |
| 180 // http://foo.com/~mike) which allow users to emit headers. This is a bad | 183 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
| 181 // idea already, but with Alternate-Protocol, it provides the ability for a | 184 // idea already, but with Alternate-Protocol, it provides the ability for a |
| 182 // single user on a multi-user system to hijack the alternate protocol. | 185 // single user on a multi-user system to hijack the alternate protocol. |
| 183 // These systems also enforce ports <1024 as restricted ports. So don't | 186 // These systems also enforce ports <1024 as restricted ports. So don't |
| 184 // allow protocol upgrades to user-controllable ports. | 187 // allow protocol upgrades to user-controllable ports. |
| 185 const int kUnrestrictedPort = 1024; | 188 const int kUnrestrictedPort = 1024; |
| 186 if (!session_->params().enable_user_alternate_protocol_ports && | 189 if (!session_->params().enable_user_alternate_protocol_ports && |
| 187 (alternative_service.port >= kUnrestrictedPort && | 190 (alternative_service.port >= kUnrestrictedPort && |
| 188 origin.port() < kUnrestrictedPort)) | 191 origin.port() < kUnrestrictedPort)) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 delete job; | 277 delete job; |
| 275 } | 278 } |
| 276 | 279 |
| 277 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 280 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
| 278 preconnect_job_set_.erase(job); | 281 preconnect_job_set_.erase(job); |
| 279 delete job; | 282 delete job; |
| 280 OnPreconnectsCompleteInternal(); | 283 OnPreconnectsCompleteInternal(); |
| 281 } | 284 } |
| 282 | 285 |
| 283 } // namespace net | 286 } // namespace net |
| OLD | NEW |