Chromium Code Reviews| Index: net/base/sdch_manager.cc |
| diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc |
| index 59589fb544723d386fa37019dd30a574cd8432d0..322a7b5c9d962f42eb19c1aeb4e36ba24436a176 100644 |
| --- a/net/base/sdch_manager.cc |
| +++ b/net/base/sdch_manager.cc |
| @@ -13,6 +13,33 @@ |
| #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| #include "net/url_request/url_request_http_job.h" |
| +namespace { |
| + |
| +// Canonicalize a URL from possibly containing a FQDN to the HDN format |
| +// specified in RFC 2965 so that trailing periods for (e.g.) domain matching |
| +// are not a concern. |
| +bool FQDNToHDN(std::string* host) { |
|
Ryan Sleevi
2014/09/18 01:22:31
1) Naming: "HDN" is not common
2) RFC 2965 is obso
Randy Smith (Not in Mondays)
2014/09/22 19:22:10
Changed to "StripTrailingDot" and edited the expla
|
| + if (host->at(host->size() - 1) != '.') |
|
Ryan Sleevi
2014/09/18 01:22:31
Why are you using at (which throws) vs [] (which d
Randy Smith (Not in Mondays)
2014/09/22 19:22:10
Because I found (*host)[] awkward and wasn't aware
|
| + return false; |
| + |
| + host->resize(host->size() - 1); |
| + return true; |
| +} |
| + |
| +void FQDNToHDNURL(GURL* gurl) { |
| + std::string host(gurl->host()); |
| + |
| + if (!FQDNToHDN(&host)) |
| + return; |
| + |
| + GURL::Replacements replacements; |
| + replacements.SetHostStr(host); |
| + *gurl = gurl->ReplaceComponents(replacements); |
| + return; |
| +} |
| + |
| +} // namespace |
| + |
| namespace net { |
| //------------------------------------------------------------------------------ |
| @@ -405,15 +432,19 @@ void SdchManager::GetVcdiffDictionary( |
| const GURL& referring_url, |
| scoped_refptr<Dictionary>* dictionary) { |
| DCHECK(CalledOnValidThread()); |
| + |
| + GURL referring_url_hdn(referring_url); |
| + FQDNToHDNURL(&referring_url_hdn); |
| + |
| *dictionary = NULL; |
| DictionaryMap::iterator it = dictionaries_.find(server_hash); |
| if (it == dictionaries_.end()) { |
| return; |
| } |
| scoped_refptr<Dictionary> matching_dictionary = it->second; |
| - if (!IsInSupportedDomain(referring_url)) |
| + if (!IsInSupportedDomain(referring_url_hdn)) |
| return; |
| - if (!matching_dictionary->CanUse(referring_url)) |
| + if (!matching_dictionary->CanUse(referring_url_hdn)) |
|
Ryan Sleevi
2014/09/18 01:22:30
1) Why do these functions use GURLs, rather than j
Randy Smith (Not in Mondays)
2014/09/22 19:22:10
I'm presuming you mean IsInSupportedDomain() and C
|
| return; |
| *dictionary = matching_dictionary; |
| } |
| @@ -424,12 +455,16 @@ void SdchManager::GetVcdiffDictionary( |
| void SdchManager::GetAvailDictionaryList(const GURL& target_url, |
| std::string* list) { |
| DCHECK(CalledOnValidThread()); |
| + |
| + GURL target_url_hdn(target_url); |
| + FQDNToHDNURL(&target_url_hdn); |
| + |
| int count = 0; |
| for (DictionaryMap::iterator it = dictionaries_.begin(); |
| it != dictionaries_.end(); ++it) { |
| - if (!IsInSupportedDomain(target_url)) |
| + if (!IsInSupportedDomain(target_url_hdn)) |
| continue; |
| - if (!it->second->CanAdvertise(target_url)) |
| + if (!it->second->CanAdvertise(target_url_hdn)) |
| continue; |
| ++count; |
| if (!list->empty()) |
| @@ -550,10 +585,15 @@ void SdchManager::AddSdchDictionary(const std::string& dictionary_text, |
| line_start = line_end + 1; |
| } |
| - if (!IsInSupportedDomain(dictionary_url)) |
| + // Convert away from FQDN to the HDN format described in RFC 2695. |
| + FQDNToHDN(&domain); |
| + GURL dictionary_url_hdn(dictionary_url); |
| + FQDNToHDNURL(&dictionary_url_hdn); |
| + |
| + if (!IsInSupportedDomain(dictionary_url_hdn)) |
| return; |
| - if (!Dictionary::CanSet(domain, path, ports, dictionary_url)) |
| + if (!Dictionary::CanSet(domain, path, ports, dictionary_url_hdn)) |
| return; |
| // TODO(jar): Remove these hacks to preclude a DOS attack involving piles of |
| @@ -574,7 +614,7 @@ void SdchManager::AddSdchDictionary(const std::string& dictionary_text, |
| << " and server hash " << server_hash; |
| Dictionary* dictionary = |
| new Dictionary(dictionary_text, header_end + 2, client_hash, |
| - dictionary_url, domain, path, expiration, ports); |
| + dictionary_url_hdn, domain, path, expiration, ports); |
| dictionaries_[server_hash] = dictionary; |
| return; |
| } |