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_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 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/strings/string16.h" | |
15 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
16 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
17 | 16 |
18 class GURL; | 17 class GURL; |
19 | 18 |
20 namespace base { | |
21 class Time; | |
22 } | |
23 | |
24 namespace url { | 19 namespace url { |
25 struct CanonHostInfo; | 20 struct CanonHostInfo; |
26 } | 21 } |
27 | 22 |
28 namespace net { | 23 namespace net { |
29 | 24 |
30 class AddressList; | 25 class AddressList; |
31 | 26 |
32 // Splits an input of the form <host>[":"<port>] into its consitituent parts. | 27 // Splits an input of the form <host>[":"<port>] into its consitituent parts. |
33 // Saves the result into |*host| and |*port|. If the input did not have | 28 // Saves the result into |*host| and |*port|. If the input did not have |
(...skipping 23 matching lines...) Expand all Loading... | |
57 NET_EXPORT std::string GetHostAndOptionalPort(const GURL& url); | 52 NET_EXPORT std::string GetHostAndOptionalPort(const GURL& url); |
58 | 53 |
59 // Returns true if |hostname| contains a non-registerable or non-assignable | 54 // Returns true if |hostname| contains a non-registerable or non-assignable |
60 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address | 55 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address |
61 // that falls in an IANA-reserved range. | 56 // that falls in an IANA-reserved range. |
62 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); | 57 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); |
63 | 58 |
64 // Returns the hostname of the current system. Returns empty string on failure. | 59 // Returns the hostname of the current system. Returns empty string on failure. |
65 NET_EXPORT std::string GetHostName(); | 60 NET_EXPORT std::string GetHostName(); |
66 | 61 |
67 // Extracts the unescaped username/password from |url|, saving the results | |
68 // into |*username| and |*password|. | |
69 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url, | |
70 base::string16* username, | |
71 base::string16* password); | |
72 | |
73 // Returns either the host from |url|, or, if the host is empty, the full spec. | 62 // Returns either the host from |url|, or, if the host is empty, the full spec. |
74 NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url); | 63 NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url); |
eroman
2016/01/13 20:21:02
This is a good candidate for url_util too
| |
75 | 64 |
76 // Canonicalizes |host| and returns it. Also fills |host_info| with | 65 // Canonicalizes |host| and returns it. Also fills |host_info| with |
77 // IP address information. |host_info| must not be NULL. | 66 // IP address information. |host_info| must not be NULL. |
78 NET_EXPORT std::string CanonicalizeHost(const std::string& host, | 67 NET_EXPORT std::string CanonicalizeHost(const std::string& host, |
79 url::CanonHostInfo* host_info); | 68 url::CanonHostInfo* host_info); |
80 | 69 |
81 // Returns true if |host| is not an IP address and is compliant with a set of | 70 // Returns true if |host| is not an IP address and is compliant with a set of |
82 // rules based on RFC 1738 and tweaked to be compatible with the real world. | 71 // rules based on RFC 1738 and tweaked to be compatible with the real world. |
83 // The rules are: | 72 // The rules are: |
84 // * One or more components separated by '.' | 73 // * One or more components separated by '.' |
85 // * Each component contains only alphanumeric characters and '-' or '_' | 74 // * Each component contains only alphanumeric characters and '-' or '_' |
86 // * The last component begins with an alphanumeric character | 75 // * The last component begins with an alphanumeric character |
87 // * Optional trailing dot after last component (means "treat as FQDN") | 76 // * Optional trailing dot after last component (means "treat as FQDN") |
88 // | 77 // |
89 // NOTE: You should only pass in hosts that have been returned from | 78 // NOTE: You should only pass in hosts that have been returned from |
90 // CanonicalizeHost(), or you may not get accurate results. | 79 // CanonicalizeHost(), or you may not get accurate results. |
91 NET_EXPORT bool IsCanonicalizedHostCompliant(const std::string& host); | 80 NET_EXPORT bool IsCanonicalizedHostCompliant(const std::string& host); |
92 | 81 |
93 // Strip the portions of |url| that aren't core to the network request. | 82 // Strip the portions of |url| that aren't core to the network request. |
94 // - user name / password | 83 // - user name / password |
95 // - reference section | 84 // - reference section |
96 NET_EXPORT GURL SimplifyUrlForRequest(const GURL& url); | 85 NET_EXPORT GURL SimplifyUrlForRequest(const GURL& url); |
eroman
2016/01/13 20:21:02
And this
| |
97 | 86 |
98 // Resolves a local hostname (such as "localhost" or "localhost6") into | 87 // Resolves a local hostname (such as "localhost" or "localhost6") into |
99 // IP endpoints with the given port. Returns true if |host| is a local | 88 // IP endpoints with the given port. Returns true if |host| is a local |
100 // hostname and false otherwise. Special IPv6 names (e.g. "localhost6") | 89 // hostname and false otherwise. Special IPv6 names (e.g. "localhost6") |
101 // will resolve to an IPv6 address only, whereas other names will | 90 // will resolve to an IPv6 address only, whereas other names will |
102 // resolve to both IPv4 and IPv6. | 91 // resolve to both IPv4 and IPv6. |
103 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, | 92 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, |
104 uint16_t port, | 93 uint16_t port, |
105 AddressList* address_list); | 94 AddressList* address_list); |
106 | 95 |
107 // Returns true if |host| is one of the local hostnames | 96 // Returns true if |host| is one of the local hostnames |
108 // (e.g. "localhost") or IP addresses (IPv4 127.0.0.0/8 or IPv6 ::1). | 97 // (e.g. "localhost") or IP addresses (IPv4 127.0.0.0/8 or IPv6 ::1). |
109 // | 98 // |
110 // Note that this function does not check for IP addresses other than | 99 // Note that this function does not check for IP addresses other than |
111 // the above, although other IP addresses may point to the local | 100 // the above, although other IP addresses may point to the local |
112 // machine. | 101 // machine. |
113 NET_EXPORT bool IsLocalhost(base::StringPiece host); | 102 NET_EXPORT bool IsLocalhost(base::StringPiece host); |
114 | 103 |
115 // Returns true if the url's host is a Google server. This should only be used | 104 // Returns true if the url's host is a Google server. This should only be used |
116 // for histograms and shouldn't be used to affect behavior. | 105 // for histograms and shouldn't be used to affect behavior. |
117 NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url); | 106 NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url); |
eroman
2016/01/13 20:21:02
And this. Basically anything which takes a GURL in
| |
118 | 107 |
119 } // namespace net | 108 } // namespace net |
120 | 109 |
121 #endif // NET_BASE_NET_UTIL_H_ | 110 #endif // NET_BASE_NET_UTIL_H_ |
OLD | NEW |