| 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_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 for (AlternativeServiceMap::reverse_iterator input_it = | 99 for (AlternativeServiceMap::reverse_iterator input_it = |
| 100 new_alternative_service_map.rbegin(); | 100 new_alternative_service_map.rbegin(); |
| 101 input_it != new_alternative_service_map.rend(); ++input_it) { | 101 input_it != new_alternative_service_map.rend(); ++input_it) { |
| 102 if (alternative_service_map_.Get(input_it->first) == | 102 if (alternative_service_map_.Get(input_it->first) == |
| 103 alternative_service_map_.end()) { | 103 alternative_service_map_.end()) { |
| 104 alternative_service_map_.Put(input_it->first, input_it->second); | 104 alternative_service_map_.Put(input_it->first, input_it->second); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS. | 108 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS. |
| 109 uint16_t canonical_port = 443; | 109 const uint16_t kCanonicalPort = 443; |
| 110 const char* canonical_scheme = "https"; | 110 const char* kCanonicalScheme = "https"; |
| 111 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 111 for (const std::string& canonical_suffix : canonical_suffixes_) { |
| 112 std::string canonical_suffix = canonical_suffixes_[i]; | 112 url::SchemeHostPort canonical_server(kCanonicalScheme, canonical_suffix, |
| 113 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix, | 113 kCanonicalPort); |
| 114 canonical_port); | |
| 115 // If we already have a valid canonical server, we're done. | 114 // If we already have a valid canonical server, we're done. |
| 116 if (ContainsKey(canonical_host_to_origin_map_, canonical_server) && | 115 if (ContainsKey(canonical_host_to_origin_map_, canonical_server) && |
| 117 (alternative_service_map_.Peek( | 116 (alternative_service_map_.Peek( |
| 118 canonical_host_to_origin_map_[canonical_server]) != | 117 canonical_host_to_origin_map_[canonical_server]) != |
| 119 alternative_service_map_.end())) { | 118 alternative_service_map_.end())) { |
| 120 continue; | 119 continue; |
| 121 } | 120 } |
| 122 // Now attempt to find a server which matches this origin and set it as | 121 // Now attempt to find a server which matches this origin and set it as |
| 123 // canonical. | 122 // canonical. |
| 124 for (AlternativeServiceMap::const_iterator it = | 123 for (AlternativeServiceMap::const_iterator it = |
| 125 alternative_service_map_.begin(); | 124 alternative_service_map_.begin(); |
| 126 it != alternative_service_map_.end(); ++it) { | 125 it != alternative_service_map_.end(); ++it) { |
| 127 if (base::EndsWith(it->first.host(), canonical_suffixes_[i], | 126 if (base::EndsWith(it->first.host(), canonical_suffix, |
| 128 base::CompareCase::INSENSITIVE_ASCII) && | 127 base::CompareCase::INSENSITIVE_ASCII) && |
| 129 it->first.scheme() == canonical_server.scheme()) { | 128 it->first.scheme() == canonical_server.scheme()) { |
| 130 canonical_host_to_origin_map_[canonical_server] = it->first; | 129 canonical_host_to_origin_map_[canonical_server] = it->first; |
| 131 break; | 130 break; |
| 132 } | 131 } |
| 133 } | 132 } |
| 134 } | 133 } |
| 135 } | 134 } |
| 136 | 135 |
| 137 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 136 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 http11_servers_.insert(host_port_pair); | 299 http11_servers_.insert(host_port_pair); |
| 301 } | 300 } |
| 302 | 301 |
| 303 void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server, | 302 void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server, |
| 304 SSLConfig* ssl_config) { | 303 SSLConfig* ssl_config) { |
| 305 if (RequiresHTTP11(server)) { | 304 if (RequiresHTTP11(server)) { |
| 306 ForceHTTP11(ssl_config); | 305 ForceHTTP11(ssl_config); |
| 307 } | 306 } |
| 308 } | 307 } |
| 309 | 308 |
| 310 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( | 309 const std::string* HttpServerPropertiesImpl::GetCanonicalSuffix( |
| 311 const std::string& host) { | 310 const std::string& host) const { |
| 312 // If this host ends with a canonical suffix, then return the canonical | 311 // If this host ends with a canonical suffix, then return the canonical |
| 313 // suffix. | 312 // suffix. |
| 314 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 313 for (const std::string& canonical_suffix : canonical_suffixes_) { |
| 315 std::string canonical_suffix = canonical_suffixes_[i]; | 314 if (base::EndsWith(host, canonical_suffix, |
| 316 if (base::EndsWith(host, canonical_suffixes_[i], | |
| 317 base::CompareCase::INSENSITIVE_ASCII)) { | 315 base::CompareCase::INSENSITIVE_ASCII)) { |
| 318 return canonical_suffix; | 316 return &canonical_suffix; |
| 319 } | 317 } |
| 320 } | 318 } |
| 321 return std::string(); | 319 return nullptr; |
| 322 } | 320 } |
| 323 | 321 |
| 324 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( | 322 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( |
| 325 const url::SchemeHostPort& origin) { | 323 const url::SchemeHostPort& origin) { |
| 326 // Copy valid alternative services into |valid_alternative_services|. | 324 // Copy valid alternative services into |valid_alternative_services|. |
| 327 AlternativeServiceVector valid_alternative_services; | 325 AlternativeServiceVector valid_alternative_services; |
| 328 const base::Time now = base::Time::Now(); | 326 const base::Time now = base::Time::Now(); |
| 329 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); | 327 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); |
| 330 if (map_it != alternative_service_map_.end()) { | 328 if (map_it != alternative_service_map_.end()) { |
| 331 HostPortPair host_port_pair(origin.host(), origin.port()); | 329 HostPortPair host_port_pair(origin.host(), origin.port()); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 if (previously_no_alternative_services && | 430 if (previously_no_alternative_services && |
| 433 !GetAlternativeServices(origin).empty()) { | 431 !GetAlternativeServices(origin).empty()) { |
| 434 // TODO(rch): Consider the case where multiple requests are started | 432 // TODO(rch): Consider the case where multiple requests are started |
| 435 // before the first completes. In this case, only one of the jobs | 433 // before the first completes. In this case, only one of the jobs |
| 436 // would reach this code, whereas all of them should should have. | 434 // would reach this code, whereas all of them should should have. |
| 437 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 435 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
| 438 } | 436 } |
| 439 | 437 |
| 440 // If this host ends with a canonical suffix, then set it as the | 438 // If this host ends with a canonical suffix, then set it as the |
| 441 // canonical host. | 439 // canonical host. |
| 442 const char* canonical_scheme = "https"; | 440 const char* kCanonicalScheme = "https"; |
| 443 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 441 if (origin.scheme() == kCanonicalScheme) { |
| 444 std::string canonical_suffix = canonical_suffixes_[i]; | 442 const std::string* canonical_suffix = GetCanonicalSuffix(origin.host()); |
| 445 // canonical suffixes only apply to HTTPS. | 443 if (canonical_suffix != nullptr) { |
| 446 if (origin.scheme() == canonical_scheme && | 444 url::SchemeHostPort canonical_server(kCanonicalScheme, *canonical_suffix, |
| 447 base::EndsWith(origin.host(), canonical_suffixes_[i], | |
| 448 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 449 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix, | |
| 450 origin.port()); | 445 origin.port()); |
| 451 canonical_host_to_origin_map_[canonical_server] = origin; | 446 canonical_host_to_origin_map_[canonical_server] = origin; |
| 452 break; | |
| 453 } | 447 } |
| 454 } | 448 } |
| 455 | |
| 456 return changed; | 449 return changed; |
| 457 } | 450 } |
| 458 | 451 |
| 459 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( | 452 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( |
| 460 const AlternativeService& alternative_service) { | 453 const AlternativeService& alternative_service) { |
| 461 // Empty host means use host of origin, callers are supposed to substitute. | 454 // Empty host means use host of origin, callers are supposed to substitute. |
| 462 DCHECK(!alternative_service.host.empty()); | 455 DCHECK(!alternative_service.host.empty()); |
| 463 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 456 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 464 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 457 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
| 465 return; | 458 return; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 } | 699 } |
| 707 } | 700 } |
| 708 | 701 |
| 709 RemoveCanonicalHost(canonical_server); | 702 RemoveCanonicalHost(canonical_server); |
| 710 return alternative_service_map_.end(); | 703 return alternative_service_map_.end(); |
| 711 } | 704 } |
| 712 | 705 |
| 713 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 706 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
| 714 HttpServerPropertiesImpl::GetCanonicalHost( | 707 HttpServerPropertiesImpl::GetCanonicalHost( |
| 715 const url::SchemeHostPort& server) const { | 708 const url::SchemeHostPort& server) const { |
| 716 const char* canonical_scheme = "https"; | 709 const char* kCanonicalScheme = "https"; |
| 717 if (server.scheme() != canonical_scheme) | 710 if (server.scheme() != kCanonicalScheme) |
| 718 return canonical_host_to_origin_map_.end(); | 711 return canonical_host_to_origin_map_.end(); |
| 719 | 712 |
| 720 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 713 const std::string* canonical_suffix = GetCanonicalSuffix(server.host()); |
| 721 std::string canonical_suffix = canonical_suffixes_[i]; | 714 if (canonical_suffix == nullptr) |
| 722 if (base::EndsWith(server.host(), canonical_suffixes_[i], | 715 return canonical_host_to_origin_map_.end(); |
| 723 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 724 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix, | |
| 725 server.port()); | |
| 726 return canonical_host_to_origin_map_.find(canonical_server); | |
| 727 } | |
| 728 } | |
| 729 | 716 |
| 730 return canonical_host_to_origin_map_.end(); | 717 url::SchemeHostPort canonical_server(kCanonicalScheme, *canonical_suffix, |
| 718 server.port()); |
| 719 return canonical_host_to_origin_map_.find(canonical_server); |
| 731 } | 720 } |
| 732 | 721 |
| 733 void HttpServerPropertiesImpl::RemoveCanonicalHost( | 722 void HttpServerPropertiesImpl::RemoveCanonicalHost( |
| 734 const url::SchemeHostPort& server) { | 723 const url::SchemeHostPort& server) { |
| 735 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); | 724 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); |
| 736 if (canonical == canonical_host_to_origin_map_.end()) | 725 if (canonical == canonical_host_to_origin_map_.end()) |
| 737 return; | 726 return; |
| 738 | 727 |
| 739 canonical_host_to_origin_map_.erase(canonical->first); | 728 canonical_host_to_origin_map_.erase(canonical->first); |
| 740 } | 729 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 783 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 795 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 784 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 796 FROM_HERE, | 785 FROM_HERE, |
| 797 base::Bind( | 786 base::Bind( |
| 798 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 787 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 799 weak_ptr_factory_.GetWeakPtr()), | 788 weak_ptr_factory_.GetWeakPtr()), |
| 800 delay); | 789 delay); |
| 801 } | 790 } |
| 802 | 791 |
| 803 } // namespace net | 792 } // namespace net |
| OLD | NEW |