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

Unified Diff: net/cookies/cookie_util.cc

Issue 354183002: Enforce SafetyMode for YouTube if prefs::kForceSafeSearch is on. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert string_util.h change Created 6 years, 5 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/cookies/cookie_util.h ('k') | net/cookies/cookie_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/cookie_util.cc
diff --git a/net/cookies/cookie_util.cc b/net/cookies/cookie_util.cc
index 3c80566e7a3e15c02e8815b2af196fc5f2e9444a..907071d1671db692fedd14b56d43628367ff57fe 100644
--- a/net/cookies/cookie_util.cc
+++ b/net/cookies/cookie_util.cc
@@ -210,6 +210,59 @@ GURL CookieOriginToURL(const std::string& domain, bool is_https) {
return GURL(scheme + "://" + host);
}
+void ParseRequestCookieLine(const std::string& header_value,
+ ParsedRequestCookies* parsed_cookies) {
+ std::string::const_iterator i = header_value.begin();
+ while (i != header_value.end()) {
+ // Here we are at the beginning of a cookie.
+
+ // Eat whitespace.
+ while (i != header_value.end() && *i == ' ') ++i;
+ if (i == header_value.end()) return;
+
+ // Find cookie name.
+ std::string::const_iterator cookie_name_beginning = i;
+ while (i != header_value.end() && *i != '=') ++i;
+ base::StringPiece cookie_name(cookie_name_beginning, i);
+
+ // Find cookie value.
+ base::StringPiece cookie_value;
+ if (i != header_value.end()) { // Cookies may have no value.
+ ++i; // Skip '='.
+ std::string::const_iterator cookie_value_beginning = i;
+ if (*i == '"') {
+ ++i; // Skip '"'.
+ while (i != header_value.end() && *i != '"') ++i;
+ if (i == header_value.end()) return;
+ ++i; // Skip '"'.
+ cookie_value = base::StringPiece(cookie_value_beginning, i);
+ // i points to character after '"', potentially a ';'
+ } else {
+ while (i != header_value.end() && *i != ';') ++i;
+ cookie_value = base::StringPiece(cookie_value_beginning, i);
+ // i points to ';' or end of string.
+ }
+ }
+ parsed_cookies->push_back(std::make_pair(cookie_name, cookie_value));
+ // Eat ';'.
+ if (i != header_value.end()) ++i;
+ }
+}
+
+std::string SerializeRequestCookieLine(
+ const ParsedRequestCookies& parsed_cookies) {
+ std::string buffer;
+ for (ParsedRequestCookies::const_iterator i = parsed_cookies.begin();
+ i != parsed_cookies.end(); ++i) {
+ if (!buffer.empty())
+ buffer.append("; ");
+ buffer.append(i->first.begin(), i->first.end());
+ buffer.push_back('=');
+ buffer.append(i->second.begin(), i->second.end());
+ }
+ return buffer;
+}
+
} // namespace cookie_utils
} // namespace net
« no previous file with comments | « net/cookies/cookie_util.h ('k') | net/cookies/cookie_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698