|
|
|
@ -7,7 +7,7 @@ use std::{
|
|
|
|
|
};
|
|
|
|
|
use termion::input::TermRead;
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "tls")]
|
|
|
|
|
#[cfg(not(feature = "disable-tls"))]
|
|
|
|
|
use native_tls::TlsConnector;
|
|
|
|
|
|
|
|
|
|
mod r#type;
|
|
|
|
@ -113,16 +113,19 @@ pub fn request(host: &str, port: &str, selector: &str, try_tls: bool) -> Result<
|
|
|
|
|
.and_then(|mut socks| socks.next().ok_or_else(|| error!("Can't create socket")))?;
|
|
|
|
|
|
|
|
|
|
// attempt tls connection
|
|
|
|
|
if cfg!(feature = "tls") && try_tls {
|
|
|
|
|
if let Ok(connector) = TlsConnector::new() {
|
|
|
|
|
let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?;
|
|
|
|
|
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
|
|
|
|
|
if let Ok(mut stream) = connector.connect(host, stream) {
|
|
|
|
|
stream.write(format!("{}\r\n", selector).as_ref())?;
|
|
|
|
|
return Ok(Stream {
|
|
|
|
|
io: Box::new(stream),
|
|
|
|
|
tls: true,
|
|
|
|
|
});
|
|
|
|
|
#[cfg(not(feature = "disable-tls"))]
|
|
|
|
|
{
|
|
|
|
|
if try_tls {
|
|
|
|
|
if let Ok(connector) = TlsConnector::new() {
|
|
|
|
|
let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?;
|
|
|
|
|
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
|
|
|
|
|
if let Ok(mut stream) = connector.connect(host, stream) {
|
|
|
|
|
stream.write(format!("{}\r\n", selector).as_ref())?;
|
|
|
|
|
return Ok(Stream {
|
|
|
|
|
io: Box::new(stream),
|
|
|
|
|
tls: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|