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_RESPONSE_HEADERS_H_ | 5 #ifndef NET_HTTP_HTTP_RESPONSE_HEADERS_H_ |
6 #define NET_HTTP_HTTP_RESPONSE_HEADERS_H_ | 6 #define NET_HTTP_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/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
16 #include "net/base/net_log.h" | 16 #include "net/base/net_log.h" |
17 #include "net/http/http_version.h" | 17 #include "net/http/http_version.h" |
| 18 #include "url/gurl.h" |
18 | 19 |
19 class Pickle; | 20 class Pickle; |
20 class PickleIterator; | 21 class PickleIterator; |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class Time; | 24 class Time; |
24 class TimeDelta; | 25 class TimeDelta; |
25 } | 26 } |
26 | 27 |
27 namespace net { | 28 namespace net { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 bool GetCharset(std::string* charset) const; | 184 bool GetCharset(std::string* charset) const; |
184 | 185 |
185 // Returns true if this response corresponds to a redirect. The target | 186 // Returns true if this response corresponds to a redirect. The target |
186 // location of the redirect is optionally returned if location is non-null. | 187 // location of the redirect is optionally returned if location is non-null. |
187 bool IsRedirect(std::string* location) const; | 188 bool IsRedirect(std::string* location) const; |
188 | 189 |
189 // Returns true if the HTTP response code passed in corresponds to a | 190 // Returns true if the HTTP response code passed in corresponds to a |
190 // redirect. | 191 // redirect. |
191 static bool IsRedirectResponseCode(int response_code); | 192 static bool IsRedirectResponseCode(int response_code); |
192 | 193 |
| 194 // Replace the Location header and HTTP status line, then mark the redirect |
| 195 // URL as safe, i.e. assume that the redirect is always allowed. |
| 196 void SetSafeRedirect(GURL new_url); |
| 197 |
| 198 // Whether |location| matches a redirect target that has been marked as safe. |
| 199 bool IsSafeRedirect(const GURL& location) const; |
| 200 |
| 201 // Whether a safe redirection target has been set. |
| 202 bool HasSafeRedirect() const; |
| 203 |
193 // Returns true if the response cannot be reused without validation. The | 204 // Returns true if the response cannot be reused without validation. The |
194 // result is relative to the current_time parameter, which is a parameter to | 205 // result is relative to the current_time parameter, which is a parameter to |
195 // support unit testing. The request_time parameter indicates the time at | 206 // support unit testing. The request_time parameter indicates the time at |
196 // which the request was made that resulted in this response, which was | 207 // which the request was made that resulted in this response, which was |
197 // received at response_time. | 208 // received at response_time. |
198 bool RequiresValidation(const base::Time& request_time, | 209 bool RequiresValidation(const base::Time& request_time, |
199 const base::Time& response_time, | 210 const base::Time& response_time, |
200 const base::Time& current_time) const; | 211 const base::Time& current_time) const; |
201 | 212 |
202 // Returns the amount of time the server claims the response is fresh from | 213 // Returns the amount of time the server claims the response is fresh from |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // null byte) and then followed by the raw null-terminated headers from the | 401 // null byte) and then followed by the raw null-terminated headers from the |
391 // input that was passed to our constructor. We preserve the input [*] to | 402 // input that was passed to our constructor. We preserve the input [*] to |
392 // maintain as much ancillary fidelity as possible (since it is sometimes | 403 // maintain as much ancillary fidelity as possible (since it is sometimes |
393 // hard to tell what may matter down-stream to a consumer of XMLHttpRequest). | 404 // hard to tell what may matter down-stream to a consumer of XMLHttpRequest). |
394 // [*] The status line may be modified. | 405 // [*] The status line may be modified. |
395 std::string raw_headers_; | 406 std::string raw_headers_; |
396 | 407 |
397 // This is the parsed HTTP response code. | 408 // This is the parsed HTTP response code. |
398 int response_code_; | 409 int response_code_; |
399 | 410 |
| 411 // A redirect target that has explicitly been marked as safe. |
| 412 GURL allowed_unsafe_redirect_url_; |
| 413 |
400 // The normalized http version (consistent with what GetStatusLine() returns). | 414 // The normalized http version (consistent with what GetStatusLine() returns). |
401 HttpVersion http_version_; | 415 HttpVersion http_version_; |
402 | 416 |
403 // The parsed http version number (not normalized). | 417 // The parsed http version number (not normalized). |
404 HttpVersion parsed_http_version_; | 418 HttpVersion parsed_http_version_; |
405 | 419 |
406 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); | 420 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); |
407 }; | 421 }; |
408 | 422 |
409 } // namespace net | 423 } // namespace net |
410 | 424 |
411 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ | 425 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ |
OLD | NEW |