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

Unified Diff: net/base/url_util.cc

Issue 1876683002: Implement SDCH Dictionary domain matching as per RFC 2965 Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Factor out IsDomainMatch from CanonicalCookie and use it in SdchDictionary. 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/base/url_util.h ('k') | net/base/url_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/url_util.cc
diff --git a/net/base/url_util.cc b/net/base/url_util.cc
index 879c746c9b3fea7584840034f6c29680f57915c0..e6add8473bb874c6dadb359011b13fe1ddd2b79d 100644
--- a/net/base/url_util.cc
+++ b/net/base/url_util.cc
@@ -438,4 +438,37 @@ bool IsLocalHostname(base::StringPiece host, bool* is_local6) {
IsNormalizedLocalhostTLD(normalized_host);
}
+bool IsDomainMatch(const std::string& domain, const std::string& host) {
+ // Can domain match in two ways; as a domain cookie (where the cookie
+ // domain begins with ".") or as a host cookie (where it doesn't).
+
+ // Some consumers of the CookieMonster expect to set cookies on
+ // URLs like http://.strange.url. To retrieve cookies in this instance,
+ // we allow matching as a host cookie even when the domain_ starts with
+ // a period.
+ if (host == domain)
+ return true;
+
+ // Domain cookie must have an initial ".". To match, it must be
+ // equal to url's host with initial period removed, or a suffix of
+ // it.
+
+ // Arguably this should only apply to "http" or "https" cookies, but
+ // extension cookie tests currently use the funtionality, and if we
+ // ever decide to implement that it should be done by preventing
+ // such cookies from being set.
+ if (domain.empty() || domain[0] != '.')
+ return false;
+
+ // The host with a "." prefixed.
+ if (domain.compare(1, std::string::npos, host) == 0)
+ return true;
+
+ // A pure suffix of the host (ok since we know the domain already
+ // starts with a ".")
+ return (host.length() > domain.length() &&
+ host.compare(host.length() - domain.length(), domain.length(),
+ domain) == 0);
+}
+
} // namespace net
« no previous file with comments | « net/base/url_util.h ('k') | net/base/url_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698