aboutsummaryrefslogtreecommitdiff
path: root/src/proxy.rs
diff options
context:
space:
mode:
authorLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-03-28 19:19:46 +0100
committerLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-03-28 19:19:46 +0100
commite1c0e90581b7ce97f87ddf43267ceb32e28447e3 (patch)
treea347bfed5552256fcbe5d54798814a1a1d24cf0a /src/proxy.rs
parentb4e12fd1165b5e3960a1294dadec45eb40893b37 (diff)
✨ (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
Diffstat (limited to 'src/proxy.rs')
-rw-r--r--src/proxy.rs80
1 files changed, 80 insertions, 0 deletions
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<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,
} \ No newline at end of file