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