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

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: davidben comments 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
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. Default is VALUES_NOT_OPTIONAL.
Ryan Sleevi 2015/07/16 02:25:44 This last sentence arguably belongs to the NameVal
estark 2015/07/16 04:52:18 Done.
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);
326 NameValuePairsIterator(std::string::const_iterator begin, 328 NameValuePairsIterator(std::string::const_iterator begin,
327 std::string::const_iterator end, 329 std::string::const_iterator end,
328 char delimiter); 330 char delimiter);
329 ~NameValuePairsIterator(); 331 ~NameValuePairsIterator();
330 332
331 // Advances the iterator to the next pair, if any. Returns true if there 333 // 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 334 // is a next pair. Use name* and value* methods to access the resultant
333 // value. 335 // value.
334 bool GetNext(); 336 bool GetNext();
335 337
(...skipping 10 matching lines...) Expand all
346 return value_is_quoted_ ? unquoted_value_.begin() : value_begin_; 348 return value_is_quoted_ ? unquoted_value_.begin() : value_begin_;
347 } 349 }
348 std::string::const_iterator value_end() const { 350 std::string::const_iterator value_end() const {
349 return value_is_quoted_ ? unquoted_value_.end() : value_end_; 351 return value_is_quoted_ ? unquoted_value_.end() : value_end_;
350 } 352 }
351 std::string value() const { 353 std::string value() const {
352 return value_is_quoted_ ? unquoted_value_ : std::string(value_begin_, 354 return value_is_quoted_ ? unquoted_value_ : std::string(value_begin_,
353 value_end_); 355 value_end_);
354 } 356 }
355 357
358 bool value_is_quoted() const { return value_is_quoted_; }
359
356 // The value before unquoting (if any). 360 // The value before unquoting (if any).
357 std::string raw_value() const { return std::string(value_begin_, 361 std::string raw_value() const { return std::string(value_begin_,
358 value_end_); } 362 value_end_); }
359 363
360 private: 364 private:
361 HttpUtil::ValuesIterator props_; 365 HttpUtil::ValuesIterator props_;
362 bool valid_; 366 bool valid_;
363 367
364 std::string::const_iterator name_begin_; 368 std::string::const_iterator name_begin_;
365 std::string::const_iterator name_end_; 369 std::string::const_iterator name_end_;
366 370
367 std::string::const_iterator value_begin_; 371 std::string::const_iterator value_begin_;
368 std::string::const_iterator value_end_; 372 std::string::const_iterator value_end_;
369 373
370 // Do not store iterators into this string. The NameValuePairsIterator 374 // Do not store iterators into this string. The NameValuePairsIterator
371 // is copyable/assignable, and if copied the copy's iterators would point 375 // is copyable/assignable, and if copied the copy's iterators would point
372 // into the original's unquoted_value_ member. 376 // into the original's unquoted_value_ member.
373 std::string unquoted_value_; 377 std::string unquoted_value_;
374 378
375 bool value_is_quoted_; 379 bool value_is_quoted_;
380
381 // True if values are required for each name/value pair; false if a
382 // name is permitted to appear without a corresponding value.
383 bool values_optional_;
376 }; 384 };
377 }; 385 };
378 386
379 } // namespace net 387 } // namespace net
380 388
381 #endif // NET_HTTP_HTTP_UTIL_H_ 389 #endif // NET_HTTP_HTTP_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698