| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cookies/cookie_util.h" | 5 #include "net/cookies/cookie_util.h" |
| 6 | 6 |
| 7 #include <cstdio> | 7 #include <cstdio> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 GURL CookieOriginToURL(const std::string& domain, bool is_https) { | 204 GURL CookieOriginToURL(const std::string& domain, bool is_https) { |
| 205 if (domain.empty()) | 205 if (domain.empty()) |
| 206 return GURL(); | 206 return GURL(); |
| 207 | 207 |
| 208 const std::string scheme = is_https ? "https" : "http"; | 208 const std::string scheme = is_https ? "https" : "http"; |
| 209 const std::string host = domain[0] == '.' ? domain.substr(1) : domain; | 209 const std::string host = domain[0] == '.' ? domain.substr(1) : domain; |
| 210 return GURL(scheme + "://" + host); | 210 return GURL(scheme + "://" + host); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void ParseRequestCookieLine(const std::string& header_value, | |
| 214 ParsedRequestCookies* parsed_cookies) { | |
| 215 std::string::const_iterator i = header_value.begin(); | |
| 216 while (i != header_value.end()) { | |
| 217 // Here we are at the beginning of a cookie. | |
| 218 | |
| 219 // Eat whitespace. | |
| 220 while (i != header_value.end() && *i == ' ') ++i; | |
| 221 if (i == header_value.end()) return; | |
| 222 | |
| 223 // Find cookie name. | |
| 224 std::string::const_iterator cookie_name_beginning = i; | |
| 225 while (i != header_value.end() && *i != '=') ++i; | |
| 226 base::StringPiece cookie_name(cookie_name_beginning, i); | |
| 227 | |
| 228 // Find cookie value. | |
| 229 base::StringPiece cookie_value; | |
| 230 if (i != header_value.end()) { // Cookies may have no value. | |
| 231 ++i; // Skip '='. | |
| 232 std::string::const_iterator cookie_value_beginning = i; | |
| 233 if (*i == '"') { | |
| 234 ++i; // Skip '"'. | |
| 235 while (i != header_value.end() && *i != '"') ++i; | |
| 236 if (i == header_value.end()) return; | |
| 237 ++i; // Skip '"'. | |
| 238 cookie_value = base::StringPiece(cookie_value_beginning, i); | |
| 239 // i points to character after '"', potentially a ';' | |
| 240 } else { | |
| 241 while (i != header_value.end() && *i != ';') ++i; | |
| 242 cookie_value = base::StringPiece(cookie_value_beginning, i); | |
| 243 // i points to ';' or end of string. | |
| 244 } | |
| 245 } | |
| 246 parsed_cookies->push_back(std::make_pair(cookie_name, cookie_value)); | |
| 247 // Eat ';'. | |
| 248 if (i != header_value.end()) ++i; | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 std::string SerializeRequestCookieLine( | |
| 253 const ParsedRequestCookies& parsed_cookies) { | |
| 254 std::string buffer; | |
| 255 for (ParsedRequestCookies::const_iterator i = parsed_cookies.begin(); | |
| 256 i != parsed_cookies.end(); ++i) { | |
| 257 if (!buffer.empty()) | |
| 258 buffer.append("; "); | |
| 259 buffer.append(i->first.begin(), i->first.end()); | |
| 260 buffer.push_back('='); | |
| 261 buffer.append(i->second.begin(), i->second.end()); | |
| 262 } | |
| 263 return buffer; | |
| 264 } | |
| 265 | |
| 266 } // namespace cookie_utils | 213 } // namespace cookie_utils |
| 267 } // namespace net | 214 } // namespace net |
| 268 | 215 |
| OLD | NEW |