OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_BASE_NET_UTIL_H_ | 5 #ifndef NET_BASE_NET_UTIL_H_ |
6 #define NET_BASE_NET_UTIL_H_ | 6 #define NET_BASE_NET_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 namespace url_parse { | 35 namespace url_parse { |
36 struct Parsed; | 36 struct Parsed; |
37 } | 37 } |
38 | 38 |
39 namespace net { | 39 namespace net { |
40 | 40 |
41 // Used by FormatUrl to specify handling of certain parts of the url. | 41 // Used by FormatUrl to specify handling of certain parts of the url. |
42 typedef uint32 FormatUrlType; | 42 typedef uint32 FormatUrlType; |
43 typedef uint32 FormatUrlTypes; | 43 typedef uint32 FormatUrlTypes; |
44 | 44 |
| 45 // Used by GetHeaderParamValue to determine how to handle quotes in the value. |
| 46 class QuoteRule { |
| 47 public: |
| 48 enum Type { |
| 49 KEEP_OUTER_QUOTES, |
| 50 REMOVE_OUTER_QUOTES, |
| 51 }; |
| 52 |
| 53 private: |
| 54 QuoteRule(); |
| 55 }; |
| 56 |
45 // Nothing is ommitted. | 57 // Nothing is ommitted. |
46 extern const FormatUrlType kFormatUrlOmitNothing; | 58 extern const FormatUrlType kFormatUrlOmitNothing; |
47 | 59 |
48 // If set, any username and password are removed. | 60 // If set, any username and password are removed. |
49 extern const FormatUrlType kFormatUrlOmitUsernamePassword; | 61 extern const FormatUrlType kFormatUrlOmitUsernamePassword; |
50 | 62 |
51 // If the scheme is 'http://', it's removed. | 63 // If the scheme is 'http://', it's removed. |
52 extern const FormatUrlType kFormatUrlOmitHTTP; | 64 extern const FormatUrlType kFormatUrlOmitHTTP; |
53 | 65 |
54 // Omits the path if it is just a slash and there is no query or ref. This is | 66 // Omits the path if it is just a slash and there is no query or ref. This is |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // Returns the empty string if the header is not found. | 129 // Returns the empty string if the header is not found. |
118 std::wstring GetSpecificHeader(const std::wstring& headers, | 130 std::wstring GetSpecificHeader(const std::wstring& headers, |
119 const std::wstring& name); | 131 const std::wstring& name); |
120 std::string GetSpecificHeader(const std::string& headers, | 132 std::string GetSpecificHeader(const std::string& headers, |
121 const std::string& name); | 133 const std::string& name); |
122 | 134 |
123 // Return the value of the HTTP response header field's parameter named | 135 // Return the value of the HTTP response header field's parameter named |
124 // 'param_name'. Returns the empty string if the parameter is not found or is | 136 // 'param_name'. Returns the empty string if the parameter is not found or is |
125 // improperly formatted. | 137 // improperly formatted. |
126 std::wstring GetHeaderParamValue(const std::wstring& field, | 138 std::wstring GetHeaderParamValue(const std::wstring& field, |
127 const std::wstring& param_name); | 139 const std::wstring& param_name, |
| 140 QuoteRule::Type quote_rule); |
128 std::string GetHeaderParamValue(const std::string& field, | 141 std::string GetHeaderParamValue(const std::string& field, |
129 const std::string& param_name); | 142 const std::string& param_name, |
| 143 QuoteRule::Type quote_rule); |
130 | 144 |
131 // Return the filename extracted from Content-Disposition header. The following | 145 // Return the filename extracted from Content-Disposition header. The following |
132 // formats are tried in order listed below: | 146 // formats are tried in order listed below: |
133 // | 147 // |
134 // 1. RFC 2047 | 148 // 1. RFC 5987 |
135 // 2. Raw-8bit-characters : | 149 // 2. RFC 2047 |
| 150 // 3. Raw-8bit-characters : |
136 // a. UTF-8, b. referrer_charset, c. default os codepage. | 151 // a. UTF-8, b. referrer_charset, c. default os codepage. |
137 // 3. %-escaped UTF-8. | 152 // 4. %-escaped UTF-8. |
138 // | 153 // |
139 // In step 2, if referrer_charset is empty(i.e. unknown), 2b is skipped. | 154 // In step 3, if referrer_charset is empty(i.e. unknown), 3b is skipped. |
140 // In step 3, the fallback charsets tried in step 2 are not tried. We | 155 // In step 4, the fallback charsets tried in step 3 are not tried. We |
141 // can consider doing that later. | 156 // can consider doing that later. |
142 // | 157 // |
143 // When a param value is ASCII, but is not in format #1 or format #3 above, | 158 // When a param value is ASCII, but is not in format #2 or format #4 above, |
144 // it is returned as it is unless it's pretty close to two supported | 159 // it is returned as it is unless it's pretty close to two supported |
145 // formats but not well-formed. In that case, an empty string is returned. | 160 // formats but not well-formed. In that case, an empty string is returned. |
146 // | 161 // |
147 // In any case, a caller must check for the empty return value and resort to | 162 // In any case, a caller must check for the empty return value and resort to |
148 // another means to get a filename (e.g. url). | 163 // another means to get a filename (e.g. url). |
149 // | 164 // |
150 // This function does not do any escaping and callers are responsible for | 165 // This function does not do any escaping and callers are responsible for |
151 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit. | 166 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit. |
152 // | 167 // |
153 // TODO(jungshik): revisit this issue. At the moment, the only caller | 168 // TODO(jungshik): revisit this issue. At the moment, the only caller |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 394 |
380 // Returns the port field of the sockaddr in |info|. | 395 // Returns the port field of the sockaddr in |info|. |
381 uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info); | 396 uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info); |
382 | 397 |
383 // Returns the value of |info's| port (in host byte ordering). | 398 // Returns the value of |info's| port (in host byte ordering). |
384 int GetPortFromAddrinfo(const struct addrinfo* info); | 399 int GetPortFromAddrinfo(const struct addrinfo* info); |
385 | 400 |
386 } // namespace net | 401 } // namespace net |
387 | 402 |
388 #endif // NET_BASE_NET_UTIL_H_ | 403 #endif // NET_BASE_NET_UTIL_H_ |
OLD | NEW |