lightstreamer_client/proxy.rs
1/// Simple class representing a Proxy configuration.
2///
3/// An instance of this class can be used through `ConnectionOptions.setProxy()` to instruct
4/// a `LightstreamerClient` to connect to the Lightstreamer Server passing through a proxy.
5///
6/// # Parameters
7///
8/// * `proxy_type`: the proxy type
9/// * `host`: the proxy host
10/// * `port`: the proxy port
11/// * `user`: the user name to be used to validate against the proxy. Optional.
12/// * `password`: the password to be used to validate against the proxy. Optional.
13#[derive(Debug)]
14pub struct Proxy {
15 proxy_type: ProxyType,
16 host: String,
17 port: u16,
18 user: Option<String>,
19 password: Option<String>,
20}
21
22impl Proxy {
23 /// Creates a new instance of `Proxy`.
24 ///
25 /// # Parameters
26 ///
27 /// * `proxy_type`: the proxy type
28 /// * `host`: the proxy host
29 /// * `port`: the proxy port
30 /// * `user`: the user name to be used to validate against the proxy. Optional.
31 /// * `password`: the password to be used to validate against the proxy. Optional.
32 pub fn new(
33 proxy_type: ProxyType,
34 host: String,
35 port: u16,
36 user: Option<String>,
37 password: Option<String>,
38 ) -> Self {
39 Proxy {
40 proxy_type,
41 host,
42 port,
43 user,
44 password,
45 }
46 }
47
48 /// Returns the proxy type.
49 pub fn get_proxy_type(&self) -> &ProxyType {
50 &self.proxy_type
51 }
52
53 /// Returns the proxy host.
54 pub fn get_host(&self) -> &str {
55 &self.host
56 }
57
58 /// Returns the proxy port.
59 pub fn get_port(&self) -> u16 {
60 self.port
61 }
62
63 /// Returns the proxy user name.
64 pub fn get_user(&self) -> Option<&String> {
65 self.user.as_ref()
66 }
67
68 /// Returns the proxy password.
69 pub fn get_password(&self) -> Option<&String> {
70 self.password.as_ref()
71 }
72}
73
74/// Represents the type of proxy.
75#[derive(Clone, Copy, Debug, PartialEq, Eq)]
76pub enum ProxyType {
77 /// HTTP proxy.
78 Http,
79 /// SOCKS4 proxy.
80 Socks4,
81 /// SOCKS5 proxy.
82 Socks5,
83}