OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "net/proxy/proxy_server.h" | 5 #include "net/proxy/proxy_server.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/string_tokenizer.h" | 9 #include "base/string_tokenizer.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // notation didn't originally exist, so if a client returns SOCKS they | 27 // notation didn't originally exist, so if a client returns SOCKS they |
28 // really meant SOCKS4. | 28 // really meant SOCKS4. |
29 return ProxyServer::SCHEME_SOCKS4; | 29 return ProxyServer::SCHEME_SOCKS4; |
30 } | 30 } |
31 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 31 if (LowerCaseEqualsASCII(begin, end, "socks4")) |
32 return ProxyServer::SCHEME_SOCKS4; | 32 return ProxyServer::SCHEME_SOCKS4; |
33 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 33 if (LowerCaseEqualsASCII(begin, end, "socks5")) |
34 return ProxyServer::SCHEME_SOCKS5; | 34 return ProxyServer::SCHEME_SOCKS5; |
35 if (LowerCaseEqualsASCII(begin, end, "direct")) | 35 if (LowerCaseEqualsASCII(begin, end, "direct")) |
36 return ProxyServer::SCHEME_DIRECT; | 36 return ProxyServer::SCHEME_DIRECT; |
| 37 if (LowerCaseEqualsASCII(begin, end, "https")) |
| 38 return ProxyServer::SCHEME_HTTPS; |
37 | 39 |
38 return ProxyServer::SCHEME_INVALID; | 40 return ProxyServer::SCHEME_INVALID; |
39 } | 41 } |
40 | 42 |
41 // Parse the proxy scheme from a URL-like representation, to a | 43 // Parse the proxy scheme from a URL-like representation, to a |
42 // ProxyServer::Scheme. This corresponds with the values used in | 44 // ProxyServer::Scheme. This corresponds with the values used in |
43 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. | 45 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. |
44 ProxyServer::Scheme GetSchemeFromURI(std::string::const_iterator begin, | 46 ProxyServer::Scheme GetSchemeFromURI(std::string::const_iterator begin, |
45 std::string::const_iterator end) { | 47 std::string::const_iterator end) { |
46 if (LowerCaseEqualsASCII(begin, end, "http")) | 48 if (LowerCaseEqualsASCII(begin, end, "http")) |
47 return ProxyServer::SCHEME_HTTP; | 49 return ProxyServer::SCHEME_HTTP; |
48 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 50 if (LowerCaseEqualsASCII(begin, end, "socks4")) |
49 return ProxyServer::SCHEME_SOCKS4; | 51 return ProxyServer::SCHEME_SOCKS4; |
50 if (LowerCaseEqualsASCII(begin, end, "socks")) | 52 if (LowerCaseEqualsASCII(begin, end, "socks")) |
51 return ProxyServer::SCHEME_SOCKS4; | 53 return ProxyServer::SCHEME_SOCKS4; |
52 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 54 if (LowerCaseEqualsASCII(begin, end, "socks5")) |
53 return ProxyServer::SCHEME_SOCKS5; | 55 return ProxyServer::SCHEME_SOCKS5; |
54 if (LowerCaseEqualsASCII(begin, end, "direct")) | 56 if (LowerCaseEqualsASCII(begin, end, "direct")) |
55 return ProxyServer::SCHEME_DIRECT; | 57 return ProxyServer::SCHEME_DIRECT; |
| 58 if (LowerCaseEqualsASCII(begin, end, "https")) |
| 59 return ProxyServer::SCHEME_HTTPS; |
56 return ProxyServer::SCHEME_INVALID; | 60 return ProxyServer::SCHEME_INVALID; |
57 } | 61 } |
58 | 62 |
59 } // namespace | 63 } // namespace |
60 | 64 |
61 std::string ProxyServer::HostNoBrackets() const { | 65 std::string ProxyServer::HostNoBrackets() const { |
62 // Doesn't make sense to call this if the URI scheme doesn't | 66 // Doesn't make sense to call this if the URI scheme doesn't |
63 // have concept of a host. | 67 // have concept of a host. |
64 DCHECK(is_valid() && !is_direct()); | 68 DCHECK(is_valid() && !is_direct()); |
65 | 69 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 switch (scheme_) { | 129 switch (scheme_) { |
126 case SCHEME_DIRECT: | 130 case SCHEME_DIRECT: |
127 return "direct://"; | 131 return "direct://"; |
128 case SCHEME_HTTP: | 132 case SCHEME_HTTP: |
129 // Leave off "http://" since it is our default scheme. | 133 // Leave off "http://" since it is our default scheme. |
130 return host_and_port(); | 134 return host_and_port(); |
131 case SCHEME_SOCKS4: | 135 case SCHEME_SOCKS4: |
132 return std::string("socks4://") + host_and_port(); | 136 return std::string("socks4://") + host_and_port(); |
133 case SCHEME_SOCKS5: | 137 case SCHEME_SOCKS5: |
134 return std::string("socks5://") + host_and_port(); | 138 return std::string("socks5://") + host_and_port(); |
| 139 case SCHEME_HTTPS: |
| 140 return std::string("https://") + host_and_port(); |
135 default: | 141 default: |
136 // Got called with an invalid scheme. | 142 // Got called with an invalid scheme. |
137 NOTREACHED(); | 143 NOTREACHED(); |
138 return std::string(); | 144 return std::string(); |
139 } | 145 } |
140 } | 146 } |
141 | 147 |
142 // static | 148 // static |
143 ProxyServer ProxyServer::FromPacString(const std::string& pac_string) { | 149 ProxyServer ProxyServer::FromPacString(const std::string& pac_string) { |
144 return FromPacString(pac_string.begin(), pac_string.end()); | 150 return FromPacString(pac_string.begin(), pac_string.end()); |
(...skipping 28 matching lines...) Expand all Loading... |
173 switch (scheme_) { | 179 switch (scheme_) { |
174 case SCHEME_DIRECT: | 180 case SCHEME_DIRECT: |
175 return "DIRECT"; | 181 return "DIRECT"; |
176 case SCHEME_HTTP: | 182 case SCHEME_HTTP: |
177 return std::string("PROXY ") + host_and_port(); | 183 return std::string("PROXY ") + host_and_port(); |
178 case SCHEME_SOCKS4: | 184 case SCHEME_SOCKS4: |
179 // For compatibility send SOCKS instead of SOCKS4. | 185 // For compatibility send SOCKS instead of SOCKS4. |
180 return std::string("SOCKS ") + host_and_port(); | 186 return std::string("SOCKS ") + host_and_port(); |
181 case SCHEME_SOCKS5: | 187 case SCHEME_SOCKS5: |
182 return std::string("SOCKS5 ") + host_and_port(); | 188 return std::string("SOCKS5 ") + host_and_port(); |
| 189 case SCHEME_HTTPS: |
| 190 return std::string("HTTPS ") + host_and_port(); |
183 default: | 191 default: |
184 // Got called with an invalid scheme. | 192 // Got called with an invalid scheme. |
185 NOTREACHED(); | 193 NOTREACHED(); |
186 return std::string(); | 194 return std::string(); |
187 } | 195 } |
188 } | 196 } |
189 | 197 |
190 // static | 198 // static |
191 int ProxyServer::GetDefaultPortForScheme(Scheme scheme) { | 199 int ProxyServer::GetDefaultPortForScheme(Scheme scheme) { |
192 switch (scheme) { | 200 switch (scheme) { |
193 case SCHEME_HTTP: | 201 case SCHEME_HTTP: |
194 return 80; | 202 return 80; |
195 case SCHEME_SOCKS4: | 203 case SCHEME_SOCKS4: |
196 case SCHEME_SOCKS5: | 204 case SCHEME_SOCKS5: |
197 return 1080; | 205 return 1080; |
| 206 case SCHEME_HTTPS: |
| 207 return 443; |
198 default: | 208 default: |
199 return -1; | 209 return -1; |
200 } | 210 } |
201 } | 211 } |
202 | 212 |
203 // static | 213 // static |
204 ProxyServer ProxyServer::FromSchemeHostAndPort( | 214 ProxyServer ProxyServer::FromSchemeHostAndPort( |
205 Scheme scheme, | 215 Scheme scheme, |
206 std::string::const_iterator begin, | 216 std::string::const_iterator begin, |
207 std::string::const_iterator end) { | 217 std::string::const_iterator end) { |
(...skipping 15 matching lines...) Expand all Loading... |
223 } | 233 } |
224 | 234 |
225 // Choose a default port number if none was given. | 235 // Choose a default port number if none was given. |
226 if (port == -1) | 236 if (port == -1) |
227 port = GetDefaultPortForScheme(scheme); | 237 port = GetDefaultPortForScheme(scheme); |
228 | 238 |
229 return ProxyServer(scheme, host, port); | 239 return ProxyServer(scheme, host, port); |
230 } | 240 } |
231 | 241 |
232 } // namespace net | 242 } // namespace net |
OLD | NEW |