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 #include "net/http/http_version.h" | 14 #include "net/http/http_version.h" |
15 | 15 |
16 class Pickle; | 16 class Pickle; |
| 17 |
| 18 namespace base { |
17 class Time; | 19 class Time; |
18 class TimeDelta; | 20 class TimeDelta; |
| 21 } |
19 | 22 |
20 namespace net { | 23 namespace net { |
21 | 24 |
22 // HttpResponseHeaders: parses and holds HTTP response headers. | 25 // HttpResponseHeaders: parses and holds HTTP response headers. |
23 class HttpResponseHeaders : | 26 class HttpResponseHeaders : |
24 public base::RefCountedThreadSafe<HttpResponseHeaders> { | 27 public base::RefCountedThreadSafe<HttpResponseHeaders> { |
25 public: | 28 public: |
26 // Parses the given raw_headers. raw_headers should be formatted thus: | 29 // Parses the given raw_headers. raw_headers should be formatted thus: |
27 // includes the http status response line, each line is \0-terminated, and | 30 // includes the http status response line, each line is \0-terminated, and |
28 // it's terminated by an empty line (ie, 2 \0s in a row). | 31 // it's terminated by an empty line (ie, 2 \0s in a row). |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 146 |
144 // Returns true if this response corresponds to a redirect. The target | 147 // Returns true if this response corresponds to a redirect. The target |
145 // location of the redirect is optionally returned if location is non-null. | 148 // location of the redirect is optionally returned if location is non-null. |
146 bool IsRedirect(std::string* location) const; | 149 bool IsRedirect(std::string* location) const; |
147 | 150 |
148 // Returns true if the response cannot be reused without validation. The | 151 // Returns true if the response cannot be reused without validation. The |
149 // result is relative to the current_time parameter, which is a parameter to | 152 // result is relative to the current_time parameter, which is a parameter to |
150 // support unit testing. The request_time parameter indicates the time at | 153 // support unit testing. The request_time parameter indicates the time at |
151 // which the request was made that resulted in this response, which was | 154 // which the request was made that resulted in this response, which was |
152 // received at response_time. | 155 // received at response_time. |
153 bool RequiresValidation(const Time& request_time, | 156 bool RequiresValidation(const base::Time& request_time, |
154 const Time& response_time, | 157 const base::Time& response_time, |
155 const Time& current_time) const; | 158 const base::Time& current_time) const; |
156 | 159 |
157 // Returns the amount of time the server claims the response is fresh from | 160 // Returns the amount of time the server claims the response is fresh from |
158 // the time the response was generated. See section 13.2.4 of RFC 2616. See | 161 // the time the response was generated. See section 13.2.4 of RFC 2616. See |
159 // RequiresValidation for a description of the response_time parameter. | 162 // RequiresValidation for a description of the response_time parameter. |
160 TimeDelta GetFreshnessLifetime(const Time& response_time) const; | 163 base::TimeDelta GetFreshnessLifetime(const base::Time& response_time) const; |
161 | 164 |
162 // Returns the age of the response. See section 13.2.3 of RFC 2616. | 165 // Returns the age of the response. See section 13.2.3 of RFC 2616. |
163 // See RequiresValidation for a description of this method's parameters. | 166 // See RequiresValidation for a description of this method's parameters. |
164 TimeDelta GetCurrentAge(const Time& request_time, | 167 base::TimeDelta GetCurrentAge(const base::Time& request_time, |
165 const Time& response_time, | 168 const base::Time& response_time, |
166 const Time& current_time) const; | 169 const base::Time& current_time) const; |
167 | 170 |
168 // The following methods extract values from the response headers. If a | 171 // The following methods extract values from the response headers. If a |
169 // value is not present, then false is returned. Otherwise, true is returned | 172 // value is not present, then false is returned. Otherwise, true is returned |
170 // and the out param is assigned to the corresponding value. | 173 // and the out param is assigned to the corresponding value. |
171 bool GetMaxAgeValue(TimeDelta* value) const; | 174 bool GetMaxAgeValue(base::TimeDelta* value) const; |
172 bool GetAgeValue(TimeDelta* value) const; | 175 bool GetAgeValue(base::TimeDelta* value) const; |
173 bool GetDateValue(Time* value) const; | 176 bool GetDateValue(base::Time* value) const; |
174 bool GetLastModifiedValue(Time* value) const; | 177 bool GetLastModifiedValue(base::Time* value) const; |
175 bool GetExpiresValue(Time* value) const; | 178 bool GetExpiresValue(base::Time* value) const; |
176 | 179 |
177 // Extracts the time value of a particular header. This method looks for the | 180 // Extracts the time value of a particular header. This method looks for the |
178 // first matching header value and parses its value as a HTTP-date. | 181 // first matching header value and parses its value as a HTTP-date. |
179 bool GetTimeValuedHeader(const std::string& name, Time* result) const; | 182 bool GetTimeValuedHeader(const std::string& name, base::Time* result) const; |
180 | 183 |
181 // Determines if this response indicates a keep-alive connection. | 184 // Determines if this response indicates a keep-alive connection. |
182 bool IsKeepAlive() const; | 185 bool IsKeepAlive() const; |
183 | 186 |
184 // Extracts the value of the Content-Length header or returns -1 if there is | 187 // Extracts the value of the Content-Length header or returns -1 if there is |
185 // no such header in the response. | 188 // no such header in the response. |
186 int64 GetContentLength() const; | 189 int64 GetContentLength() const; |
187 | 190 |
188 // Returns the HTTP response code. This is 0 if the response code text seems | 191 // Returns the HTTP response code. This is 0 if the response code text seems |
189 // to exist but could not be parsed. Otherwise, it defaults to 200 if the | 192 // to exist but could not be parsed. Otherwise, it defaults to 200 if the |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 280 |
278 // The parsed http version number (not normalized). | 281 // The parsed http version number (not normalized). |
279 HttpVersion parsed_http_version_; | 282 HttpVersion parsed_http_version_; |
280 | 283 |
281 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); | 284 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); |
282 }; | 285 }; |
283 | 286 |
284 } // namespace net | 287 } // namespace net |
285 | 288 |
286 #endif // NET_HTTP_RESPONSE_HEADERS_H_ | 289 #endif // NET_HTTP_RESPONSE_HEADERS_H_ |
287 | |
OLD | NEW |