| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_RESPONSE_HEADERS_H_ | 5 #ifndef NET_HTTP_RESPONSE_HEADERS_H_ |
| 6 #define NET_HTTP_RESPONSE_HEADERS_H_ | 6 #define NET_HTTP_RESPONSE_HEADERS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 | 14 |
| 15 class Pickle; | 15 class Pickle; |
| 16 class Time; | 16 class Time; |
| 17 class TimeDelta; | 17 class TimeDelta; |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 // HttpResponseHeaders: parses and holds HTTP response headers. | 21 // HttpResponseHeaders: parses and holds HTTP response headers. |
| 22 class HttpResponseHeaders : | 22 class HttpResponseHeaders : |
| 23 public base::RefCountedThreadSafe<HttpResponseHeaders> { | 23 public base::RefCountedThreadSafe<HttpResponseHeaders> { |
| 24 public: | 24 public: |
| 25 // Parses the given raw_headers. raw_headers should be formatted thus: | 25 // Parses the given raw_headers. raw_headers should be formatted thus: |
| 26 // includes the http status response line, each line is \0-terminated, and | 26 // includes the http status response line, each line is \0-terminated, and |
| 27 // it's terminated by an empty line (ie, 2 \0s in a row). | 27 // it's terminated by an empty line (ie, 2 \0s in a row). |
| 28 // (Note that line continuations should have already been joined; |
| 29 // see HttpUtil::AssembleRawHeaders) |
| 28 // | 30 // |
| 29 // NOTE: For now, raw_headers is not really 'raw' in that this constructor is | 31 // NOTE: For now, raw_headers is not really 'raw' in that this constructor is |
| 30 // called with a 'NativeMB' string on Windows because WinHTTP does not allow | 32 // called with a 'NativeMB' string on Windows because WinHTTP does not allow |
| 31 // us to access the raw byte sequence as sent by a web server. In any case, | 33 // us to access the raw byte sequence as sent by a web server. In any case, |
| 32 // HttpResponseHeaders does not perform any encoding changes on the input. | 34 // HttpResponseHeaders does not perform any encoding changes on the input. |
| 33 // | 35 // |
| 34 explicit HttpResponseHeaders(const std::string& raw_headers); | 36 explicit HttpResponseHeaders(const std::string& raw_headers); |
| 35 | 37 |
| 36 // Initializes from the representation stored in the given pickle. The data | 38 // Initializes from the representation stored in the given pickle. The data |
| 37 // for this object is found relative to the given pickle_iter, which should | 39 // for this object is found relative to the given pickle_iter, which should |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 199 |
| 198 // Tries to extract the status line from a header block, given the first | 200 // Tries to extract the status line from a header block, given the first |
| 199 // line of said header block. If the status line is malformed, we'll construc
t | 201 // line of said header block. If the status line is malformed, we'll construc
t |
| 200 // a valid one. Example input: | 202 // a valid one. Example input: |
| 201 // HTTP/1.1 200 OK | 203 // HTTP/1.1 200 OK |
| 202 // with line_begin and end pointing at the begin and end of this line. | 204 // with line_begin and end pointing at the begin and end of this line. |
| 203 // Output will be a normalized version of this, with a trailing \n. | 205 // Output will be a normalized version of this, with a trailing \n. |
| 204 void ParseStatusLine(std::string::const_iterator line_begin, | 206 void ParseStatusLine(std::string::const_iterator line_begin, |
| 205 std::string::const_iterator line_end); | 207 std::string::const_iterator line_end); |
| 206 | 208 |
| 207 // Tries to extract the header line from a header block, given a single | |
| 208 // line of said header block. If the header is malformed, we skip it. | |
| 209 // Example input: | |
| 210 // Content-Length : text/html; charset=utf-8 | |
| 211 void ParseHeaderLine(std::string::const_iterator line_begin, | |
| 212 std::string::const_iterator line_end); | |
| 213 | |
| 214 // Find the header in our list (case-insensitive) starting with parsed_ at | 209 // Find the header in our list (case-insensitive) starting with parsed_ at |
| 215 // index |from|. Returns string::npos if not found. | 210 // index |from|. Returns string::npos if not found. |
| 216 size_t FindHeader(size_t from, const std::string& name) const; | 211 size_t FindHeader(size_t from, const std::string& name) const; |
| 217 | 212 |
| 218 // Add a header->value pair to our list. If we already have header in our | 213 // Add a header->value pair to our list. If we already have header in our |
| 219 // list, append the value to it. | 214 // list, append the value to it. |
| 220 void AddHeader(std::string::const_iterator name_begin, | 215 void AddHeader(std::string::const_iterator name_begin, |
| 221 std::string::const_iterator name_end, | 216 std::string::const_iterator name_end, |
| 222 std::string::const_iterator value_begin, | 217 std::string::const_iterator value_begin, |
| 223 std::string::const_iterator value_end); | 218 std::string::const_iterator value_end); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 247 bool is_continuation() const { return name_begin == name_end; } | 242 bool is_continuation() const { return name_begin == name_end; } |
| 248 }; | 243 }; |
| 249 typedef std::vector<ParsedHeader> HeaderList; | 244 typedef std::vector<ParsedHeader> HeaderList; |
| 250 | 245 |
| 251 // We keep a list of ParsedHeader objects. These tell us where to locate the | 246 // We keep a list of ParsedHeader objects. These tell us where to locate the |
| 252 // header-value pairs within raw_headers_. | 247 // header-value pairs within raw_headers_. |
| 253 HeaderList parsed_; | 248 HeaderList parsed_; |
| 254 | 249 |
| 255 // The raw_headers_ consists of the normalized status line (terminated with a | 250 // The raw_headers_ consists of the normalized status line (terminated with a |
| 256 // null byte) and then followed by the raw null-terminated headers from the | 251 // null byte) and then followed by the raw null-terminated headers from the |
| 257 // input that was passed to our constructor. We preserve the input to | 252 // input that was passed to our constructor. We preserve the input [*] to |
| 258 // maintain as much ancillary fidelity as possible (since it is sometimes | 253 // maintain as much ancillary fidelity as possible (since it is sometimes |
| 259 // hard to tell what may matter down-stream to a consumer of XMLHttpRequest). | 254 // hard to tell what may matter down-stream to a consumer of XMLHttpRequest). |
| 255 // [*] The status line may be modified. |
| 260 std::string raw_headers_; | 256 std::string raw_headers_; |
| 261 | 257 |
| 262 // This is the parsed HTTP response code. | 258 // This is the parsed HTTP response code. |
| 263 int response_code_; | 259 int response_code_; |
| 264 | 260 |
| 265 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); | 261 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); |
| 266 }; | 262 }; |
| 267 | 263 |
| 268 } // namespace net | 264 } // namespace net |
| 269 | 265 |
| 270 #endif // NET_HTTP_RESPONSE_HEADERS_H_ | 266 #endif // NET_HTTP_RESPONSE_HEADERS_H_ |
| 271 | 267 |
| OLD | NEW |