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

Side by Side Diff: net/http/http_util.h

Issue 1211363005: Parse HPKP report-uri and persist in TransportSecurityPersister (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetNext() fix Created 5 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 unified diff | Download patch
« no previous file with comments | « net/http/http_security_headers_unittest.cc ('k') | net/http/http_util.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 (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 #ifndef NET_HTTP_HTTP_UTIL_H_ 5 #ifndef NET_HTTP_HTTP_UTIL_H_
6 #define NET_HTTP_HTTP_UTIL_H_ 6 #define NET_HTTP_HTTP_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 22
23 namespace net { 23 namespace net {
24 24
25 class NET_EXPORT HttpUtil { 25 class NET_EXPORT HttpUtil {
26 public: 26 public:
27 // Returns the absolute URL, to be used for the http request. This url is 27 // Returns the absolute URL, to be used for the http request. This url is
28 // made up of the protocol, host, [port], path, [query]. Everything else 28 // made up of the protocol, host, [port], path, [query]. Everything else
29 // is stripped (username, password, reference). 29 // is stripped (username, password, reference).
30 static std::string SpecForRequest(const GURL& url); 30 static std::string SpecForRequest(const GURL& url);
31 31
32 // Locates the next occurance of delimiter in line, skipping over quoted
33 // strings (e.g., commas will not be treated as delimiters if they appear
34 // within a quoted string). Returns the offset of the found delimiter or
35 // line.size() if no delimiter was found.
36 static size_t FindDelimiter(const std::string& line,
37 size_t search_start,
38 char delimiter);
39
40 // Parses the value of a Content-Type header. The resulting mime_type and 32 // Parses the value of a Content-Type header. The resulting mime_type and
41 // charset values are normalized to lowercase. The mime_type and charset 33 // charset values are normalized to lowercase. The mime_type and charset
42 // output values are only modified if the content_type_str contains a mime 34 // output values are only modified if the content_type_str contains a mime
43 // type and charset value, respectively. The boundary output value is 35 // type and charset value, respectively. The boundary output value is
44 // optional and will be assigned the (quoted) value of the boundary 36 // optional and will be assigned the (quoted) value of the boundary
45 // paramter, if any. 37 // paramter, if any.
46 static void ParseContentType(const std::string& content_type_str, 38 static void ParseContentType(const std::string& content_type_str,
47 std::string* mime_type, 39 std::string* mime_type,
48 std::string* charset, 40 std::string* charset,
49 bool* had_charset, 41 bool* had_charset,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 308
317 // Iterates over a delimited sequence of name-value pairs in an HTTP header. 309 // Iterates over a delimited sequence of name-value pairs in an HTTP header.
318 // Each pair consists of a token (the name), an equals sign, and either a 310 // Each pair consists of a token (the name), an equals sign, and either a
319 // token or quoted-string (the value). Arbitrary HTTP LWS is permitted outside 311 // token or quoted-string (the value). Arbitrary HTTP LWS is permitted outside
320 // of and between names, values, and delimiters. 312 // of and between names, values, and delimiters.
321 // 313 //
322 // String iterators returned from this class' methods may be invalidated upon 314 // String iterators returned from this class' methods may be invalidated upon
323 // calls to GetNext() or after the NameValuePairsIterator is destroyed. 315 // calls to GetNext() or after the NameValuePairsIterator is destroyed.
324 class NET_EXPORT NameValuePairsIterator { 316 class NET_EXPORT NameValuePairsIterator {
325 public: 317 public:
318 // Whether or not values are optional. VALUES_OPTIONAL allows
319 // e.g. name1=value1;name2;name3=value3, whereas VALUES_NOT_OPTIONAL
320 // will treat it as a parse error because name2 does not have a
321 // corresponding equals sign.
322 enum OptionalValues { VALUES_OPTIONAL, VALUES_NOT_OPTIONAL };
323
324 NameValuePairsIterator(std::string::const_iterator begin,
325 std::string::const_iterator end,
326 char delimiter,
327 OptionalValues optional_values);
328
329 // Treats values as not optional by default (VALUES_NOT_OPTIONAL).
326 NameValuePairsIterator(std::string::const_iterator begin, 330 NameValuePairsIterator(std::string::const_iterator begin,
327 std::string::const_iterator end, 331 std::string::const_iterator end,
328 char delimiter); 332 char delimiter);
333
329 ~NameValuePairsIterator(); 334 ~NameValuePairsIterator();
330 335
331 // Advances the iterator to the next pair, if any. Returns true if there 336 // Advances the iterator to the next pair, if any. Returns true if there
332 // is a next pair. Use name* and value* methods to access the resultant 337 // is a next pair. Use name* and value* methods to access the resultant
333 // value. 338 // value.
334 bool GetNext(); 339 bool GetNext();
335 340
336 // Returns false if there was a parse error. 341 // Returns false if there was a parse error.
337 bool valid() const { return valid_; } 342 bool valid() const { return valid_; }
338 343
339 // The name of the current name-value pair. 344 // The name of the current name-value pair.
340 std::string::const_iterator name_begin() const { return name_begin_; } 345 std::string::const_iterator name_begin() const { return name_begin_; }
341 std::string::const_iterator name_end() const { return name_end_; } 346 std::string::const_iterator name_end() const { return name_end_; }
342 std::string name() const { return std::string(name_begin_, name_end_); } 347 std::string name() const { return std::string(name_begin_, name_end_); }
343 348
344 // The value of the current name-value pair. 349 // The value of the current name-value pair.
345 std::string::const_iterator value_begin() const { 350 std::string::const_iterator value_begin() const {
346 return value_is_quoted_ ? unquoted_value_.begin() : value_begin_; 351 return value_is_quoted_ ? unquoted_value_.begin() : value_begin_;
347 } 352 }
348 std::string::const_iterator value_end() const { 353 std::string::const_iterator value_end() const {
349 return value_is_quoted_ ? unquoted_value_.end() : value_end_; 354 return value_is_quoted_ ? unquoted_value_.end() : value_end_;
350 } 355 }
351 std::string value() const { 356 std::string value() const {
352 return value_is_quoted_ ? unquoted_value_ : std::string(value_begin_, 357 return value_is_quoted_ ? unquoted_value_ : std::string(value_begin_,
353 value_end_); 358 value_end_);
354 } 359 }
355 360
361 bool value_is_quoted() const { return value_is_quoted_; }
362
356 // The value before unquoting (if any). 363 // The value before unquoting (if any).
357 std::string raw_value() const { return std::string(value_begin_, 364 std::string raw_value() const { return std::string(value_begin_,
358 value_end_); } 365 value_end_); }
359 366
360 private: 367 private:
361 HttpUtil::ValuesIterator props_; 368 HttpUtil::ValuesIterator props_;
362 bool valid_; 369 bool valid_;
363 370
364 std::string::const_iterator name_begin_; 371 std::string::const_iterator name_begin_;
365 std::string::const_iterator name_end_; 372 std::string::const_iterator name_end_;
366 373
367 std::string::const_iterator value_begin_; 374 std::string::const_iterator value_begin_;
368 std::string::const_iterator value_end_; 375 std::string::const_iterator value_end_;
369 376
370 // Do not store iterators into this string. The NameValuePairsIterator 377 // Do not store iterators into this string. The NameValuePairsIterator
371 // is copyable/assignable, and if copied the copy's iterators would point 378 // is copyable/assignable, and if copied the copy's iterators would point
372 // into the original's unquoted_value_ member. 379 // into the original's unquoted_value_ member.
373 std::string unquoted_value_; 380 std::string unquoted_value_;
374 381
375 bool value_is_quoted_; 382 bool value_is_quoted_;
383
384 // True if values are required for each name/value pair; false if a
385 // name is permitted to appear without a corresponding value.
386 bool values_optional_;
376 }; 387 };
377 }; 388 };
378 389
379 } // namespace net 390 } // namespace net
380 391
381 #endif // NET_HTTP_HTTP_UTIL_H_ 392 #endif // NET_HTTP_HTTP_UTIL_H_
OLDNEW
« no previous file with comments | « net/http/http_security_headers_unittest.cc ('k') | net/http/http_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698