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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... | |
39 // output values are only modified if the content_type_str contains a mime | 39 // output values are only modified if the content_type_str contains a mime |
40 // type and charset value, respectively. The boundary output value is | 40 // type and charset value, respectively. The boundary output value is |
41 // optional and will be assigned the (quoted) value of the boundary | 41 // optional and will be assigned the (quoted) value of the boundary |
42 // paramter, if any. | 42 // paramter, if any. |
43 static void ParseContentType(const std::string& content_type_str, | 43 static void ParseContentType(const std::string& content_type_str, |
44 std::string* mime_type, | 44 std::string* mime_type, |
45 std::string* charset, | 45 std::string* charset, |
46 bool* had_charset, | 46 bool* had_charset, |
47 std::string* boundary); | 47 std::string* boundary); |
48 | 48 |
49 // Scans the headers and look for the first "Range" header in |headers|, | 49 // Parses the value of a "Range" header as defined in RFC 7233 Secion 2.1. |
eroman
2016/12/29 01:15:28
typo: Section
mmenke
2016/12/29 02:14:28
Done.
| |
50 // if "Range" exists and the first one of it is well formatted then returns | |
51 // true, |ranges| will contain a list of valid ranges. If return | |
52 // value is false then values in |ranges| should not be used. The format of | |
53 // "Range" header is defined in RFC 7233 Section 2.1. | |
54 // https://tools.ietf.org/html/rfc7233#section-2.1 | 50 // https://tools.ietf.org/html/rfc7233#section-2.1 |
55 static bool ParseRanges(const std::string& headers, | 51 // Returns false on failure. |
56 std::vector<HttpByteRange>* ranges); | |
57 | |
58 // Same thing as ParseRanges except the Range header is known and its value | |
59 // is directly passed in, rather than requiring searching through a string. | |
60 static bool ParseRangeHeader(const std::string& range_specifier, | 52 static bool ParseRangeHeader(const std::string& range_specifier, |
61 std::vector<HttpByteRange>* ranges); | 53 std::vector<HttpByteRange>* ranges); |
62 | 54 |
63 // Extracts the values in a Content-Range header and returns true if they are | 55 // Extracts the values in a Content-Range header and returns true if they are |
64 // valid for a 206 response; otherwise returns false. | 56 // valid for a 206 response; otherwise returns false. |
65 // The following values will be outputted: | 57 // The following values will be outputted: |
66 // |*first_byte_position| = inclusive position of the first byte of the range | 58 // |*first_byte_position| = inclusive position of the first byte of the range |
67 // |*last_byte_position| = inclusive position of the last byte of the range | 59 // |*last_byte_position| = inclusive position of the last byte of the range |
68 // |*instance_length| = size in bytes of the object requested | 60 // |*instance_length| = size in bytes of the object requested |
69 // If any of the above values is unknown, its value will be -1. | 61 // If any of the above values is unknown, its value will be -1. |
(...skipping 23 matching lines...) Expand all Loading... | |
93 // named |name|. | 85 // named |name|. |
94 static bool IsSafeHeader(const std::string& name); | 86 static bool IsSafeHeader(const std::string& name); |
95 | 87 |
96 // Returns true if |name| is a valid HTTP header name. | 88 // Returns true if |name| is a valid HTTP header name. |
97 static bool IsValidHeaderName(const base::StringPiece& name); | 89 static bool IsValidHeaderName(const base::StringPiece& name); |
98 | 90 |
99 // Returns false if |value| contains NUL or CRLF. This method does not perform | 91 // Returns false if |value| contains NUL or CRLF. This method does not perform |
100 // a fully RFC-2616-compliant header value validation. | 92 // a fully RFC-2616-compliant header value validation. |
101 static bool IsValidHeaderValue(const base::StringPiece& value); | 93 static bool IsValidHeaderValue(const base::StringPiece& value); |
102 | 94 |
103 // Strips all header lines from |headers| whose name matches | |
104 // |headers_to_remove|. |headers_to_remove| is a list of null-terminated | |
105 // lower-case header names, with array length |headers_to_remove_len|. | |
106 // Returns the stripped header lines list, separated by "\r\n". | |
107 static std::string StripHeaders(const std::string& headers, | |
108 const char* const headers_to_remove[], | |
109 size_t headers_to_remove_len); | |
110 | |
111 // Multiple occurances of some headers cannot be coalesced into a comma- | 95 // Multiple occurances of some headers cannot be coalesced into a comma- |
112 // separated list since their values are (or contain) unquoted HTTP-date | 96 // separated list since their values are (or contain) unquoted HTTP-date |
113 // values, which may contain a comma (see RFC 2616 section 3.3.1). | 97 // values, which may contain a comma (see RFC 2616 section 3.3.1). |
114 static bool IsNonCoalescingHeader(std::string::const_iterator name_begin, | 98 static bool IsNonCoalescingHeader(std::string::const_iterator name_begin, |
115 std::string::const_iterator name_end); | 99 std::string::const_iterator name_end); |
116 static bool IsNonCoalescingHeader(const std::string& name) { | 100 static bool IsNonCoalescingHeader(const std::string& name) { |
117 return IsNonCoalescingHeader(name.begin(), name.end()); | 101 return IsNonCoalescingHeader(name.begin(), name.end()); |
118 } | 102 } |
119 | 103 |
120 // Return true if the character is HTTP "linear white space" (SP | HT). | 104 // Return true if the character is HTTP "linear white space" (SP | HT). |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 // True if quotes values are required to be properly quoted; false if | 438 // True if quotes values are required to be properly quoted; false if |
455 // mismatched quotes and other problems with quoted values should be more | 439 // mismatched quotes and other problems with quoted values should be more |
456 // or less gracefully treated as valid. | 440 // or less gracefully treated as valid. |
457 bool strict_quotes_; | 441 bool strict_quotes_; |
458 }; | 442 }; |
459 }; | 443 }; |
460 | 444 |
461 } // namespace net | 445 } // namespace net |
462 | 446 |
463 #endif // NET_HTTP_HTTP_UTIL_H_ | 447 #endif // NET_HTTP_HTTP_UTIL_H_ |
OLD | NEW |