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 #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 Loading... |
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 Loading... |
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. |
| 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 30 matching lines...) Expand all Loading... |
366 | 368 |
367 std::string::const_iterator value_begin_; | 369 std::string::const_iterator value_begin_; |
368 std::string::const_iterator value_end_; | 370 std::string::const_iterator value_end_; |
369 | 371 |
370 // Do not store iterators into this string. The NameValuePairsIterator | 372 // Do not store iterators into this string. The NameValuePairsIterator |
371 // is copyable/assignable, and if copied the copy's iterators would point | 373 // is copyable/assignable, and if copied the copy's iterators would point |
372 // into the original's unquoted_value_ member. | 374 // into the original's unquoted_value_ member. |
373 std::string unquoted_value_; | 375 std::string unquoted_value_; |
374 | 376 |
375 bool value_is_quoted_; | 377 bool value_is_quoted_; |
| 378 |
| 379 // True if values are required for each name/value pair; false if a |
| 380 // name is permitted to appear without a corresponding value. |
| 381 bool values_optional_; |
376 }; | 382 }; |
377 }; | 383 }; |
378 | 384 |
379 } // namespace net | 385 } // namespace net |
380 | 386 |
381 #endif // NET_HTTP_HTTP_UTIL_H_ | 387 #endif // NET_HTTP_HTTP_UTIL_H_ |
OLD | NEW |