| 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 // HttpRequestHeaders manages the request headers. | 5 // HttpRequestHeaders manages the request headers. |
| 6 // It maintains these in a vector of header key/value pairs, thereby maintaining | 6 // It maintains these in a vector of header key/value pairs, thereby maintaining |
| 7 // the order of the headers. This means that any lookups are linear time | 7 // the order of the headers. This means that any lookups are linear time |
| 8 // operations. | 8 // operations. |
| 9 | 9 |
| 10 #ifndef NET_HTTP_HTTP_REQUEST_HEADERS_H_ | 10 #ifndef NET_HTTP_HTTP_REQUEST_HEADERS_H_ |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Sets the header value pair for |key| and |value|, if |key| does not exist. | 105 // Sets the header value pair for |key| and |value|, if |key| does not exist. |
| 106 // If |key| already exists, the call is a no-op. | 106 // If |key| already exists, the call is a no-op. |
| 107 // When comparing |key|, case is ignored. | 107 // When comparing |key|, case is ignored. |
| 108 void SetHeaderIfMissing(const base::StringPiece& key, | 108 void SetHeaderIfMissing(const base::StringPiece& key, |
| 109 const base::StringPiece& value); | 109 const base::StringPiece& value); |
| 110 | 110 |
| 111 // Removes the first header that matches (case insensitive) |key|. | 111 // Removes the first header that matches (case insensitive) |key|. |
| 112 void RemoveHeader(const base::StringPiece& key); | 112 void RemoveHeader(const base::StringPiece& key); |
| 113 | 113 |
| 114 // Parses the header from a string and calls SetHeader() with it. This string | 114 // Parses the header from a string and calls SetHeader() with it. This string |
| 115 // should not contain any CRLF. As per RFC7230 Section 3.2, the format is: | 115 // should not contain any CRLF. Individual CR and LF are also prohibited. |
| 116 // As per RFC7230 Section 3.2, the format is: |
| 116 // | 117 // |
| 117 // header-field = field-name ":" OWS field-value OWS | 118 // header-field = field-name ":" OWS field-value OWS |
| 118 // | 119 // |
| 119 // field-name = token | 120 // field-name = token |
| 120 // field-value = *( field-content / obs-fold ) | 121 // field-value = *( field-content / obs-fold ) |
| 121 // field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] | 122 // field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] |
| 122 // field-vchar = VCHAR / obs-text | 123 // field-vchar = VCHAR / obs-text |
| 123 // | 124 // |
| 124 // obs-fold = CRLF 1*( SP / HTAB ) | 125 // obs-fold = CRLF 1*( SP / HTAB ) |
| 125 // ; obsolete line folding | 126 // ; obsolete line folding |
| 126 // ; see Section 3.2.4 | 127 // ; see Section 3.2.4 |
| 127 // | 128 // |
| 128 // AddHeaderFromString() will trim any LWS surrounding the | 129 // AddHeaderFromString() will trim any LWS surrounding the |
| 129 // field-content. | 130 // field-content. |
| 130 void AddHeaderFromString(const base::StringPiece& header_line); | 131 void AddHeaderFromString(const base::StringPiece& header_line); |
| 131 | 132 |
| 132 // Same thing as AddHeaderFromString() except that |headers| is a "\r\n" | 133 // Same thing as AddHeaderFromString() except that |headers| is a "\r\n" |
| 133 // delimited string of header lines. It will split up the string by "\r\n" | 134 // delimited string of header lines. It will split up the string by "\r\n" |
| 134 // and call AddHeaderFromString() on each. | 135 // and call AddHeaderFromString() on each. Individual "\r" and "\n" are also |
| 136 // treated as delimeters, to protect against "header smuggling", but callers |
| 137 // should always use "\r\n" as the delimiter. |
| 135 void AddHeadersFromString(const base::StringPiece& headers); | 138 void AddHeadersFromString(const base::StringPiece& headers); |
| 136 | 139 |
| 137 // Calls SetHeader() on each header from |other|, maintaining order. | 140 // Calls SetHeader() on each header from |other|, maintaining order. |
| 138 void MergeFrom(const HttpRequestHeaders& other); | 141 void MergeFrom(const HttpRequestHeaders& other); |
| 139 | 142 |
| 140 // Copies from |other| to |this|. | 143 // Copies from |other| to |this|. |
| 141 void CopyFrom(const HttpRequestHeaders& other) { | 144 void CopyFrom(const HttpRequestHeaders& other) { |
| 142 *this = other; | 145 *this = other; |
| 143 } | 146 } |
| 144 | 147 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 175 // Allow the copy construction and operator= to facilitate copying in | 178 // Allow the copy construction and operator= to facilitate copying in |
| 176 // HttpRequestHeaders. | 179 // HttpRequestHeaders. |
| 177 // TODO(willchan): Investigate to see if we can remove the need to copy | 180 // TODO(willchan): Investigate to see if we can remove the need to copy |
| 178 // HttpRequestHeaders. | 181 // HttpRequestHeaders. |
| 179 // DISALLOW_COPY_AND_ASSIGN(HttpRequestHeaders); | 182 // DISALLOW_COPY_AND_ASSIGN(HttpRequestHeaders); |
| 180 }; | 183 }; |
| 181 | 184 |
| 182 } // namespace net | 185 } // namespace net |
| 183 | 186 |
| 184 #endif // NET_HTTP_HTTP_REQUEST_HEADERS_H_ | 187 #endif // NET_HTTP_HTTP_REQUEST_HEADERS_H_ |
| OLD | NEW |