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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/strings/string_tokenizer.h" | 12 #include "base/strings/string_tokenizer.h" |
| 13 #include "base/time/time.h" |
13 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
14 #include "net/http/http_byte_range.h" | 15 #include "net/http/http_byte_range.h" |
15 #include "net/http/http_version.h" | 16 #include "net/http/http_version.h" |
16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
17 | 18 |
18 // This is a macro to support extending this string literal at compile time. | 19 // This is a macro to support extending this string literal at compile time. |
19 // Please excuse me polluting your global namespace! | 20 // Please excuse me polluting your global namespace! |
20 #define HTTP_LWS " \t" | 21 #define HTTP_LWS " \t" |
21 | 22 |
22 namespace net { | 23 namespace net { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // "Range" header is defined in RFC 7233 Section 2.1. | 60 // "Range" header is defined in RFC 7233 Section 2.1. |
60 // https://tools.ietf.org/html/rfc7233#section-2.1 | 61 // https://tools.ietf.org/html/rfc7233#section-2.1 |
61 static bool ParseRanges(const std::string& headers, | 62 static bool ParseRanges(const std::string& headers, |
62 std::vector<HttpByteRange>* ranges); | 63 std::vector<HttpByteRange>* ranges); |
63 | 64 |
64 // Same thing as ParseRanges except the Range header is known and its value | 65 // Same thing as ParseRanges except the Range header is known and its value |
65 // is directly passed in, rather than requiring searching through a string. | 66 // is directly passed in, rather than requiring searching through a string. |
66 static bool ParseRangeHeader(const std::string& range_specifier, | 67 static bool ParseRangeHeader(const std::string& range_specifier, |
67 std::vector<HttpByteRange>* ranges); | 68 std::vector<HttpByteRange>* ranges); |
68 | 69 |
| 70 // Parses a Retry-After header that is either an absolute date/time or a |
| 71 // number of seconds in the future. Interprets absolute times as relative to |
| 72 // |now|. If |retry_after_string| is successfully parsed and indicates a time |
| 73 // that is not in the past, fills in |*retry_after| and returns true; |
| 74 // otherwise, returns false. |
| 75 static bool ParseRetryAfterHeader(const std::string& retry_after_string, |
| 76 base::Time now, |
| 77 base::TimeDelta* retry_after); |
| 78 |
69 // Scans the '\r\n'-delimited headers for the given header name. Returns | 79 // Scans the '\r\n'-delimited headers for the given header name. Returns |
70 // true if a match is found. Input is assumed to be well-formed. | 80 // true if a match is found. Input is assumed to be well-formed. |
71 // TODO(darin): kill this | 81 // TODO(darin): kill this |
72 static bool HasHeader(const std::string& headers, const char* name); | 82 static bool HasHeader(const std::string& headers, const char* name); |
73 | 83 |
74 // Returns true if it is safe to allow users and scripts to specify the header | 84 // Returns true if it is safe to allow users and scripts to specify the header |
75 // named |name|. | 85 // named |name|. |
76 static bool IsSafeHeader(const std::string& name); | 86 static bool IsSafeHeader(const std::string& name); |
77 | 87 |
78 // Returns true if |name| is a valid HTTP header name. | 88 // Returns true if |name| is a valid HTTP header name. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // into the original's unquoted_value_ member. | 367 // into the original's unquoted_value_ member. |
358 std::string unquoted_value_; | 368 std::string unquoted_value_; |
359 | 369 |
360 bool value_is_quoted_; | 370 bool value_is_quoted_; |
361 }; | 371 }; |
362 }; | 372 }; |
363 | 373 |
364 } // namespace net | 374 } // namespace net |
365 | 375 |
366 #endif // NET_HTTP_HTTP_UTIL_H_ | 376 #endif // NET_HTTP_HTTP_UTIL_H_ |
OLD | NEW |