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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/base/url_util.h" 5 #include "net/base/url_util.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <netinet/in.h> 10 #include <netinet/in.h>
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 return true; 431 return true;
432 } 432 }
433 433
434 if (is_local6) 434 if (is_local6)
435 *is_local6 = false; 435 *is_local6 = false;
436 return normalized_host == "localhost" || 436 return normalized_host == "localhost" ||
437 normalized_host == "localhost.localdomain" || 437 normalized_host == "localhost.localdomain" ||
438 IsNormalizedLocalhostTLD(normalized_host); 438 IsNormalizedLocalhostTLD(normalized_host);
439 } 439 }
440 440
441 bool IsDomainMatch(const std::string& domain, const std::string& host) {
442 // Can domain match in two ways; as a domain cookie (where the cookie
443 // domain begins with ".") or as a host cookie (where it doesn't).
444
445 // Some consumers of the CookieMonster expect to set cookies on
446 // URLs like http://.strange.url. To retrieve cookies in this instance,
447 // we allow matching as a host cookie even when the domain_ starts with
448 // a period.
449 if (host == domain)
450 return true;
451
452 // Domain cookie must have an initial ".". To match, it must be
453 // equal to url's host with initial period removed, or a suffix of
454 // it.
455
456 // Arguably this should only apply to "http" or "https" cookies, but
457 // extension cookie tests currently use the funtionality, and if we
458 // ever decide to implement that it should be done by preventing
459 // such cookies from being set.
460 if (domain.empty() || domain[0] != '.')
461 return false;
462
463 // The host with a "." prefixed.
464 if (domain.compare(1, std::string::npos, host) == 0)
465 return true;
466
467 // A pure suffix of the host (ok since we know the domain already
468 // starts with a ".")
469 return (host.length() > domain.length() &&
470 host.compare(host.length() - domain.length(), domain.length(),
471 domain) == 0);
472 }
473
441 } // namespace net 474 } // namespace net
OLDNEW
« 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