Skip to main content

aria2_protocol/socks/
proxy_url.rs

1use super::{Socks4Connector, Socks5Connector, SocksConnectorEnum};
2use crate::proxy::{ProxyProtocol, ProxyUrl};
3
4impl ProxyUrl {
5    /// Create the matching connector for SOCKS URLs.
6    ///
7    /// Panics when called for an HTTP or HTTPS proxy URL.
8    pub fn create_connector(&self) -> SocksConnectorEnum {
9        match self.protocol {
10            ProxyProtocol::Socks4 => SocksConnectorEnum::Socks4(Socks4Connector::new(
11                self.username.clone().unwrap_or_default(),
12            )),
13            ProxyProtocol::Socks5 => SocksConnectorEnum::Socks5(Socks5Connector::new(
14                self.username.clone(),
15                self.password.clone(),
16            )),
17            ProxyProtocol::Http | ProxyProtocol::Https => {
18                panic!("HTTP/HTTPS connectors not yet implemented")
19            }
20        }
21    }
22}