use super::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ProxyType {
Http,
Https,
Socks5,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Proxy {
pub proxy_type: ProxyType,
pub host: String,
pub port: u16,
pub username: Option<String>,
pub password: Option<String>,
}
impl Proxy {
pub fn http<H: AsRef<str>>(host: H, port: u16) -> Self {
Self::new(ProxyType::Http, host, port)
}
pub fn https<H: AsRef<str>>(host: H, port: u16) -> Self {
Self::new(ProxyType::Https, host, port)
}
pub fn socks5<H: AsRef<str>>(host: H, port: u16) -> Self {
Self::new(ProxyType::Socks5, host, port)
}
pub fn auth<U: AsRef<str>, P: AsRef<str>>(mut self, username: U, password: P) -> Self {
self.username = Some(username.as_ref().to_owned());
self.password = Some(password.as_ref().to_owned());
self
}
fn new<H: AsRef<str>>(proxy_type: ProxyType, host: H, port: u16) -> Self {
Self {
proxy_type,
host: host.as_ref().to_owned(),
port,
username: None,
password: None,
}
}
}
pub struct ProxyTunnelStream {
pub(super) inner: BoxAsyncReadWrite,
pub(super) pre_read_data: Vec<u8>,
}
pub struct SyncProxyTunnelStream {
pub(super) inner: BoxReadWrite,
pub(super) pre_read_data: Vec<u8>,
}