From e1c0e90581b7ce97f87ddf43267ceb32e28447e3 Mon Sep 17 00:00:00 2001 From: Daniel López Azaña Date: Thu, 28 Mar 2024 19:19:46 +0100 Subject: ✨ (client_listener.rs): Implement Debug trait for ClientListener for better logging ♻️ (connection_details.rs): Refactor ConnectionDetails to use Option for optional fields ♻️ (connection_details.rs): Change new constructor to accept &str and convert to String ✨ (connection_details.rs): Implement Debug trait for ConnectionDetails ♻️ (connection_options.rs): Implement Debug trait for ConnectionOptions ♻️ (lightstreamer_client.rs): Refactor LightstreamerClient to use Option for server_address and adapter_set ✨ (lightstreamer_client.rs): Implement Debug trait for LightstreamerClient ♻️ (main.rs): Update subscribe_to_channel function to use new control.txt URL and parameters ♻️ (main.rs): Update main function to use Option<&str> when creating LightstreamerClient ✨ (proxy.rs): Add Proxy struct and ProxyType enum to handle proxy configurations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/proxy.rs | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src/proxy.rs') diff --git a/src/proxy.rs b/src/proxy.rs index 48b2758..9a8add8 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -1,3 +1,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, + password: Option, +} +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, + password: Option, + ) -> 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, } \ No newline at end of file -- cgit v1.2.3