Rename trait HttpsStream -> ReadWrite and make it public

Also provide an example of how to use it.
This commit is contained in:
Martin Algesten
2021-12-23 16:43:50 +01:00
parent 140aa5901f
commit 6e5041044b
5 changed files with 96 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
use crate::error::Error;
use crate::error::ErrorKind;
use crate::stream::{HttpsStream, TlsConnector};
use crate::stream::{ReadWrite, TlsConnector};
use std::net::TcpStream;
use std::sync::Arc;
@@ -11,11 +11,7 @@ pub(crate) fn default_tls_config() -> std::sync::Arc<dyn TlsConnector> {
}
impl TlsConnector for native_tls::TlsConnector {
fn connect(
&self,
dns_name: &str,
tcp_stream: TcpStream,
) -> Result<Box<dyn HttpsStream>, Error> {
fn connect(&self, dns_name: &str, tcp_stream: TcpStream) -> Result<Box<dyn ReadWrite>, Error> {
let stream =
native_tls::TlsConnector::connect(self, dns_name, tcp_stream).map_err(|e| {
ErrorKind::ConnectionFailed
@@ -28,7 +24,7 @@ impl TlsConnector for native_tls::TlsConnector {
}
#[cfg(feature = "native-tls")]
impl HttpsStream for native_tls::TlsStream<TcpStream> {
impl ReadWrite for native_tls::TlsStream<TcpStream> {
fn socket(&self) -> Option<&TcpStream> {
Some(self.get_ref())
}