Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Unified Diff: net/http/http_server_properties_impl.cc

Issue 1824903002: Change the AlternativeServiceMap with SchemeOriginPair key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_server_properties_impl.cc
diff --git a/net/http/http_server_properties_impl.cc b/net/http/http_server_properties_impl.cc
index a0a6bfe644f35fbde0ac8fb00d0c1a98d830f307..36bfb027cc98172d3435105eabd74ec4c7ef6d83 100644
--- a/net/http/http_server_properties_impl.cc
+++ b/net/http/http_server_properties_impl.cc
@@ -104,29 +104,29 @@ void HttpServerPropertiesImpl::InitializeAlternativeServiceServers(
}
}
- // Attempt to find canonical servers.
- uint16_t canonical_ports[] = {80, 443};
+ // Attempt to find canonical servers. Canonical suffixes only apply to HTTPS.
+ uint16_t canonical_ports = 443;
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
std::string canonical_suffix = canonical_suffixes_[i];
- for (size_t j = 0; j < arraysize(canonical_ports); ++j) {
- HostPortPair canonical_host(canonical_suffix, canonical_ports[j]);
- // If we already have a valid canonical server, we're done.
- if (ContainsKey(canonical_host_to_origin_map_, canonical_host) &&
- (alternative_service_map_.Peek(
- canonical_host_to_origin_map_[canonical_host]) !=
- alternative_service_map_.end())) {
- continue;
- }
- // Now attempt to find a server which matches this origin and set it as
- // canonical.
- for (AlternativeServiceMap::const_iterator it =
- alternative_service_map_.begin();
- it != alternative_service_map_.end(); ++it) {
- if (base::EndsWith(it->first.host(), canonical_suffixes_[i],
- base::CompareCase::INSENSITIVE_ASCII)) {
- canonical_host_to_origin_map_[canonical_host] = it->first;
- break;
- }
+ url::SchemeHostPort canonical_host("https", canonical_suffix,
+ canonical_ports);
+ // If we already have a valid canonical server, we're done.
+ if (ContainsKey(canonical_host_to_origin_map_, canonical_host) &&
+ (alternative_service_map_.Peek(
+ canonical_host_to_origin_map_[canonical_host]) !=
+ alternative_service_map_.end())) {
+ continue;
+ }
+ // Now attempt to find a server which matches this origin and set it as
+ // canonical.
+ for (AlternativeServiceMap::const_iterator it =
+ alternative_service_map_.begin();
+ it != alternative_service_map_.end(); ++it) {
+ if (base::EndsWith(it->first.host(), canonical_suffixes_[i],
+ base::CompareCase::INSENSITIVE_ASCII) &&
+ it->first.scheme() == "https") {
+ canonical_host_to_origin_map_[canonical_host] = it->first;
+ break;
}
}
}
@@ -234,16 +234,15 @@ void HttpServerPropertiesImpl::Clear() {
}
bool HttpServerPropertiesImpl::SupportsRequestPriority(
- const HostPortPair& host_port_pair) {
+ const url::SchemeHostPort& server) {
DCHECK(CalledOnValidThread());
- if (host_port_pair.host().empty())
+ if (server.host().empty())
return false;
-
- if (GetSupportsSpdy(host_port_pair))
+ if (GetSupportsSpdy(HostPortPair::FromSchemeHostPort(server)))
return true;
const AlternativeServiceVector alternative_service_vector =
- GetAlternativeServices(host_port_pair);
+ GetAlternativeServices(server);
for (const AlternativeService& alternative_service :
alternative_service_vector) {
if (alternative_service.protocol == QUIC) {
@@ -321,7 +320,7 @@ std::string HttpServerPropertiesImpl::GetCanonicalSuffix(
}
AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
- const HostPortPair& origin) {
+ const url::SchemeHostPort& origin) {
// Copy valid alternative services into |valid_alternative_services|.
AlternativeServiceVector valid_alternative_services;
const base::Time now = base::Time::Now();
@@ -340,7 +339,8 @@ AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
// If the alternative service is equivalent to the origin (same host, same
// port, and both TCP), then there is already a Job for it, so do not
// return it here.
- if (origin.Equals(alternative_service.host_port_pair()) &&
+ if (HostPortPair::FromSchemeHostPort(origin).Equals(
+ alternative_service.host_port_pair()) &&
NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol &&
alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
++it;
@@ -391,7 +391,7 @@ AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
}
bool HttpServerPropertiesImpl::SetAlternativeService(
- const HostPortPair& origin,
+ const url::SchemeHostPort& origin,
const AlternativeService& alternative_service,
base::Time expiration) {
return SetAlternativeServices(
@@ -401,7 +401,7 @@ bool HttpServerPropertiesImpl::SetAlternativeService(
}
bool HttpServerPropertiesImpl::SetAlternativeServices(
- const HostPortPair& origin,
+ const url::SchemeHostPort& origin,
const AlternativeServiceInfoVector& alternative_service_info_vector) {
AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin);
@@ -439,9 +439,12 @@ bool HttpServerPropertiesImpl::SetAlternativeServices(
// canonical host.
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
std::string canonical_suffix = canonical_suffixes_[i];
- if (base::EndsWith(origin.host(), canonical_suffixes_[i],
+ // canonical suffixes only apply to HTTPS.
+ if (origin.scheme() == "https" &&
+ base::EndsWith(origin.host(), canonical_suffixes_[i],
base::CompareCase::INSENSITIVE_ASCII)) {
- HostPortPair canonical_host(canonical_suffix, origin.port());
+ url::SchemeHostPort canonical_host(origin.scheme(), canonical_suffix,
+ origin.port());
canonical_host_to_origin_map_[canonical_host] = origin;
break;
}
@@ -506,7 +509,7 @@ void HttpServerPropertiesImpl::ConfirmAlternativeService(
}
void HttpServerPropertiesImpl::ClearAlternativeServices(
- const HostPortPair& origin) {
+ const url::SchemeHostPort& origin) {
RemoveCanonicalHost(origin);
AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin);
@@ -527,7 +530,8 @@ HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue()
scoped_ptr<base::ListValue> dict_list(new base::ListValue);
for (const auto& alternative_service_map_item : alternative_service_map_) {
scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue);
- const HostPortPair& host_port_pair = alternative_service_map_item.first;
+ const HostPortPair& host_port_pair =
+ HostPortPair::FromSchemeHostPort(alternative_service_map_item.first);
for (const AlternativeServiceInfo& alternative_service_info :
alternative_service_map_item.second) {
std::string alternative_service_string(
@@ -686,19 +690,22 @@ void HttpServerPropertiesImpl::SetMaxServerConfigsStoredInProperties(
AlternativeServiceMap::const_iterator
HttpServerPropertiesImpl::GetAlternateProtocolIterator(
- const HostPortPair& server) {
+ const url::SchemeHostPort& server) {
AlternativeServiceMap::const_iterator it =
alternative_service_map_.Get(server);
if (it != alternative_service_map_.end())
return it;
+ if (server.scheme() != "https")
+ return alternative_service_map_.end();
+
CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server);
if (canonical == canonical_host_to_origin_map_.end()) {
return alternative_service_map_.end();
}
- const HostPortPair canonical_host_port = canonical->second;
- it = alternative_service_map_.Get(canonical_host_port);
+ const url::SchemeHostPort canonical_scheme_host_port = canonical->second;
+ it = alternative_service_map_.Get(canonical_scheme_host_port);
if (it == alternative_service_map_.end()) {
return alternative_service_map_.end();
}
@@ -707,25 +714,26 @@ HttpServerPropertiesImpl::GetAlternateProtocolIterator(
AlternativeService alternative_service(
alternative_service_info.alternative_service);
if (alternative_service.host.empty()) {
- alternative_service.host = canonical_host_port.host();
+ alternative_service.host = canonical_scheme_host_port.host();
}
if (!IsAlternativeServiceBroken(alternative_service)) {
return it;
}
}
- RemoveCanonicalHost(canonical_host_port);
+ RemoveCanonicalHost(canonical_scheme_host_port);
return alternative_service_map_.end();
}
HttpServerPropertiesImpl::CanonicalHostMap::const_iterator
-HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const {
+HttpServerPropertiesImpl::GetCanonicalHost(url::SchemeHostPort server) const {
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
std::string canonical_suffix = canonical_suffixes_[i];
if (base::EndsWith(server.host(), canonical_suffixes_[i],
base::CompareCase::INSENSITIVE_ASCII)) {
- HostPortPair canonical_host(canonical_suffix, server.port());
- return canonical_host_to_origin_map_.find(canonical_host);
+ url::SchemeHostPort canonical_origin(server.scheme(), canonical_suffix,
+ server.port());
+ return canonical_host_to_origin_map_.find(canonical_origin);
}
}
@@ -733,7 +741,7 @@ HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const {
}
void HttpServerPropertiesImpl::RemoveCanonicalHost(
- const HostPortPair& server) {
+ const url::SchemeHostPort& server) {
CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server);
if (canonical == canonical_host_to_origin_map_.end())
return;
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698