Chromium Code Reviews| 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 "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/http/http_byte_range.h" | 14 #include "net/http/http_byte_range.h" |
| 15 #include "net/http/http_version.h" | 15 #include "net/http/http_version.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 // This is a macro to support extending this string literal at compile time. | 18 // This is a macro to support extending this string literal at compile time. |
| 19 // Please excuse me polluting your global namespace! | 19 // Please excuse me polluting your global namespace! |
| 20 #define HTTP_LWS " \t" | 20 #define HTTP_LWS " \t" |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 class HttpResponseHeaders; | |
| 25 | |
| 24 class NET_EXPORT HttpUtil { | 26 class NET_EXPORT HttpUtil { |
| 25 public: | 27 public: |
| 26 // Returns the absolute path of the URL, to be used for the http request. | 28 // Returns the absolute path of the URL, to be used for the http request. |
| 27 // The absolute path starts with a '/' and may contain a query. | 29 // The absolute path starts with a '/' and may contain a query. |
| 28 static std::string PathForRequest(const GURL& url); | 30 static std::string PathForRequest(const GURL& url); |
| 29 | 31 |
| 30 // Returns the absolute URL, to be used for the http request. This url is | 32 // Returns the absolute URL, to be used for the http request. This url is |
| 31 // made up of the protocol, host, [port], path, [query]. Everything else | 33 // made up of the protocol, host, [port], path, [query]. Everything else |
| 32 // is stripped (username, password, reference). | 34 // is stripped (username, password, reference). |
| 33 static std::string SpecForRequest(const GURL& url); | 35 static std::string SpecForRequest(const GURL& url); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 59 // "Range" header is defined in RFC 2616 Section 14.35.1. | 61 // "Range" header is defined in RFC 2616 Section 14.35.1. |
| 60 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 | 62 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 |
| 61 static bool ParseRanges(const std::string& headers, | 63 static bool ParseRanges(const std::string& headers, |
| 62 std::vector<HttpByteRange>* ranges); | 64 std::vector<HttpByteRange>* ranges); |
| 63 | 65 |
| 64 // Same thing as ParseRanges except the Range header is known and its value | 66 // 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. | 67 // is directly passed in, rather than requiring searching through a string. |
| 66 static bool ParseRangeHeader(const std::string& range_specifier, | 68 static bool ParseRangeHeader(const std::string& range_specifier, |
| 67 std::vector<HttpByteRange>* ranges); | 69 std::vector<HttpByteRange>* ranges); |
| 68 | 70 |
| 71 // Updates Content-Length and Content-Range headers in the |headers| | |
|
rvargas (doing something else)
2014/03/05 19:47:33
tiny nit: go as close to 80 columns as possible.
kinuko
2014/03/06 04:11:29
Done.
| |
| 72 // to include the right content length and range for |byte_range|. | |
| 73 // This also updates HTTP status line if |replace_status_line| is true. | |
| 74 // |byte_range| must be valid, otherwise this returns false and does | |
| 75 // not update |headers|. | |
| 76 static bool UpdateResponseHeadersWithRange( | |
|
rvargas (doing something else)
2014/03/05 19:47:33
Did you consider making this a member of ResponseH
kinuko
2014/03/06 04:11:29
Makes sense, I was worried that no other http util
| |
| 77 const HttpByteRange& byte_range, | |
| 78 int64 resource_size, | |
| 79 bool replace_status_line, | |
| 80 HttpResponseHeaders* headers); | |
| 81 | |
| 69 // Scans the '\r\n'-delimited headers for the given header name. Returns | 82 // 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. | 83 // true if a match is found. Input is assumed to be well-formed. |
| 71 // TODO(darin): kill this | 84 // TODO(darin): kill this |
| 72 static bool HasHeader(const std::string& headers, const char* name); | 85 static bool HasHeader(const std::string& headers, const char* name); |
| 73 | 86 |
| 74 // Returns true if it is safe to allow users and scripts to specify the header | 87 // Returns true if it is safe to allow users and scripts to specify the header |
| 75 // named |name|. | 88 // named |name|. |
| 76 static bool IsSafeHeader(const std::string& name); | 89 static bool IsSafeHeader(const std::string& name); |
| 77 | 90 |
| 78 // Strips all header lines from |headers| whose name matches | 91 // Strips all header lines from |headers| whose name matches |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 // into the original's unquoted_value_ member. | 363 // into the original's unquoted_value_ member. |
| 351 std::string unquoted_value_; | 364 std::string unquoted_value_; |
| 352 | 365 |
| 353 bool value_is_quoted_; | 366 bool value_is_quoted_; |
| 354 }; | 367 }; |
| 355 }; | 368 }; |
| 356 | 369 |
| 357 } // namespace net | 370 } // namespace net |
| 358 | 371 |
| 359 #endif // NET_HTTP_HTTP_UTIL_H_ | 372 #endif // NET_HTTP_HTTP_UTIL_H_ |
| OLD | NEW |