OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PROXY_PROXY_SERVER_H_ | 5 #ifndef NET_PROXY_PROXY_SERVER_H_ |
6 #define NET_PROXY_PROXY_SERVER_H_ | 6 #define NET_PROXY_PROXY_SERVER_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
(...skipping 13 matching lines...) Expand all Loading... |
24 // The type of proxy. These are defined as bit flags so they can be ORed | 24 // The type of proxy. These are defined as bit flags so they can be ORed |
25 // together to pass as the |scheme_bit_field| argument to | 25 // together to pass as the |scheme_bit_field| argument to |
26 // ProxyService::RemoveProxiesWithoutScheme(). | 26 // ProxyService::RemoveProxiesWithoutScheme(). |
27 enum Scheme { | 27 enum Scheme { |
28 SCHEME_INVALID = 1 << 0, | 28 SCHEME_INVALID = 1 << 0, |
29 SCHEME_DIRECT = 1 << 1, | 29 SCHEME_DIRECT = 1 << 1, |
30 SCHEME_HTTP = 1 << 2, | 30 SCHEME_HTTP = 1 << 2, |
31 SCHEME_SOCKS4 = 1 << 3, | 31 SCHEME_SOCKS4 = 1 << 3, |
32 SCHEME_SOCKS5 = 1 << 4, | 32 SCHEME_SOCKS5 = 1 << 4, |
33 SCHEME_HTTPS = 1 << 5, | 33 SCHEME_HTTPS = 1 << 5, |
| 34 // A QUIC proxy is an HTTP proxy in which QUIC is used as the transport, |
| 35 // instead of TCP. |
| 36 SCHEME_QUIC = 1 << 6, |
34 }; | 37 }; |
35 | 38 |
36 // Default copy-constructor and assignment operator are OK! | 39 // Default copy-constructor and assignment operator are OK! |
37 | 40 |
38 // Constructs an invalid ProxyServer. | 41 // Constructs an invalid ProxyServer. |
39 ProxyServer() : scheme_(SCHEME_INVALID) {} | 42 ProxyServer() : scheme_(SCHEME_INVALID) {} |
40 | 43 |
41 ProxyServer(Scheme scheme, const HostPortPair& host_port_pair); | 44 ProxyServer(Scheme scheme, const HostPortPair& host_port_pair); |
42 | 45 |
43 bool is_valid() const { return scheme_ != SCHEME_INVALID; } | 46 bool is_valid() const { return scheme_ != SCHEME_INVALID; } |
44 | 47 |
45 // Gets the proxy's scheme (i.e. SOCKS4, SOCKS5, HTTP) | 48 // Gets the proxy's scheme (i.e. SOCKS4, SOCKS5, HTTP) |
46 Scheme scheme() const { return scheme_; } | 49 Scheme scheme() const { return scheme_; } |
47 | 50 |
48 // Returns true if this ProxyServer is actually just a DIRECT connection. | 51 // Returns true if this ProxyServer is actually just a DIRECT connection. |
49 bool is_direct() const { return scheme_ == SCHEME_DIRECT; } | 52 bool is_direct() const { return scheme_ == SCHEME_DIRECT; } |
50 | 53 |
51 // Returns true if this ProxyServer is an HTTP proxy. | 54 // Returns true if this ProxyServer is an HTTP proxy. |
52 bool is_http() const { return scheme_ == SCHEME_HTTP; } | 55 bool is_http() const { return scheme_ == SCHEME_HTTP; } |
53 | 56 |
54 // Returns true if this ProxyServer is an HTTPS proxy. | 57 // Returns true if this ProxyServer is an HTTPS proxy. |
55 bool is_https() const { return scheme_ == SCHEME_HTTPS; } | 58 bool is_https() const { return scheme_ == SCHEME_HTTPS; } |
56 | 59 |
57 // Returns true if this ProxyServer is a SOCKS proxy. | 60 // Returns true if this ProxyServer is a SOCKS proxy. |
58 bool is_socks() const { | 61 bool is_socks() const { |
59 return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5; | 62 return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5; |
60 } | 63 } |
61 | 64 |
| 65 // Returns true if this ProxyServer is a QUIC proxy. |
| 66 bool is_quic() const { return scheme_ == SCHEME_QUIC; } |
| 67 |
62 const HostPortPair& host_port_pair() const; | 68 const HostPortPair& host_port_pair() const; |
63 | 69 |
64 // Parses from an input with format: | 70 // Parses from an input with format: |
65 // [<scheme>"://"]<server>[":"<port>] | 71 // [<scheme>"://"]<server>[":"<port>] |
66 // | 72 // |
67 // Both <scheme> and <port> are optional. If <scheme> is omitted, it will be | 73 // Both <scheme> and <port> are optional. If <scheme> is omitted, it will be |
68 // assumed as |default_scheme|. If <port> is omitted, it will be assumed as | 74 // assumed as |default_scheme|. If <port> is omitted, it will be assumed as |
69 // the default port for the chosen scheme (80 for "http", 1080 for "socks"). | 75 // the default port for the chosen scheme (80 for "http", 1080 for "socks"). |
70 // | 76 // |
71 // If parsing fails the instance will be set to invalid. | 77 // If parsing fails the instance will be set to invalid. |
72 // | 78 // |
73 // Examples (for |default_scheme| = SCHEME_HTTP ): | 79 // Examples (for |default_scheme| = SCHEME_HTTP ): |
74 // "foopy" {scheme=HTTP, host="foopy", port=80} | 80 // "foopy" {scheme=HTTP, host="foopy", port=80} |
75 // "socks://foopy" {scheme=SOCKS5, host="foopy", port=1080} | 81 // "socks://foopy" {scheme=SOCKS5, host="foopy", port=1080} |
76 // "socks4://foopy" {scheme=SOCKS4, host="foopy", port=1080} | 82 // "socks4://foopy" {scheme=SOCKS4, host="foopy", port=1080} |
77 // "socks5://foopy" {scheme=SOCKS5, host="foopy", port=1080} | 83 // "socks5://foopy" {scheme=SOCKS5, host="foopy", port=1080} |
78 // "http://foopy:17" {scheme=HTTP, host="foopy", port=17} | 84 // "http://foopy:17" {scheme=HTTP, host="foopy", port=17} |
79 // "https://foopy:17" {scheme=HTTPS, host="foopy", port=17} | 85 // "https://foopy:17" {scheme=HTTPS, host="foopy", port=17} |
| 86 // "quic://foopy:17" {scheme=QUIC, host="foopy", port=17} |
80 // "direct://" {scheme=DIRECT} | 87 // "direct://" {scheme=DIRECT} |
81 // "foopy:X" INVALID -- bad port. | 88 // "foopy:X" INVALID -- bad port. |
82 static ProxyServer FromURI(const std::string& uri, Scheme default_scheme); | 89 static ProxyServer FromURI(const std::string& uri, Scheme default_scheme); |
83 static ProxyServer FromURI(std::string::const_iterator uri_begin, | 90 static ProxyServer FromURI(std::string::const_iterator uri_begin, |
84 std::string::const_iterator uri_end, | 91 std::string::const_iterator uri_end, |
85 Scheme default_scheme); | 92 Scheme default_scheme); |
86 | 93 |
87 // Formats as a URI string. This does the reverse of FromURI. | 94 // Formats as a URI string. This does the reverse of FromURI. |
88 std::string ToURI() const; | 95 std::string ToURI() const; |
89 | 96 |
90 // Parses from a PAC string result. | 97 // Parses from a PAC string result. |
91 // | 98 // |
92 // If <port> is omitted, it will be assumed as the default port for the | 99 // If <port> is omitted, it will be assumed as the default port for the |
93 // chosen scheme (80 for "http", 1080 for "socks"). | 100 // chosen scheme (80 for "http", 1080 for "socks"). |
94 // | 101 // |
95 // If parsing fails the instance will be set to invalid. | 102 // If parsing fails the instance will be set to invalid. |
96 // | 103 // |
97 // Examples: | 104 // Examples: |
98 // "PROXY foopy:19" {scheme=HTTP, host="foopy", port=19} | 105 // "PROXY foopy:19" {scheme=HTTP, host="foopy", port=19} |
99 // "DIRECT" {scheme=DIRECT} | 106 // "DIRECT" {scheme=DIRECT} |
100 // "SOCKS5 foopy" {scheme=SOCKS5, host="foopy", port=1080} | 107 // "SOCKS5 foopy" {scheme=SOCKS5, host="foopy", port=1080} |
101 // "HTTPS foopy:123" {scheme=HTTPS, host="foopy", port=123} | 108 // "HTTPS foopy:123" {scheme=HTTPS, host="foopy", port=123} |
| 109 // "QUIC foopy:123" {scheme=QUIC, host="foopy", port=123} |
102 // "BLAH xxx:xx" INVALID | 110 // "BLAH xxx:xx" INVALID |
103 static ProxyServer FromPacString(const std::string& pac_string); | 111 static ProxyServer FromPacString(const std::string& pac_string); |
104 static ProxyServer FromPacString(std::string::const_iterator pac_string_begin, | 112 static ProxyServer FromPacString(std::string::const_iterator pac_string_begin, |
105 std::string::const_iterator pac_string_end); | 113 std::string::const_iterator pac_string_end); |
106 | 114 |
107 // Returns a ProxyServer representing DIRECT connections. | 115 // Returns a ProxyServer representing DIRECT connections. |
108 static ProxyServer Direct() { | 116 static ProxyServer Direct() { |
109 return ProxyServer(SCHEME_DIRECT, HostPortPair()); | 117 return ProxyServer(SCHEME_DIRECT, HostPortPair()); |
110 } | 118 } |
111 | 119 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 172 |
165 Scheme scheme_; | 173 Scheme scheme_; |
166 HostPortPair host_port_pair_; | 174 HostPortPair host_port_pair_; |
167 }; | 175 }; |
168 | 176 |
169 typedef std::pair<HostPortPair, ProxyServer> HostPortProxyPair; | 177 typedef std::pair<HostPortPair, ProxyServer> HostPortProxyPair; |
170 | 178 |
171 } // namespace net | 179 } // namespace net |
172 | 180 |
173 #endif // NET_PROXY_PROXY_SERVER_H_ | 181 #endif // NET_PROXY_PROXY_SERVER_H_ |
OLD | NEW |