Remove unsafe usage by taking advantage of new Decoder::unwrap function.

This commit is contained in:
Drake Tetreault
2020-01-16 17:27:52 -08:00
committed by Martin Algesten
parent 787b11b1e4
commit af6491cd59
4 changed files with 50 additions and 89 deletions

View File

@@ -5,6 +5,8 @@ use std::net::ToSocketAddrs;
use std::time::Duration;
use std::time::Instant;
use chunked_transfer::Decoder as ChunkDecoder;
#[cfg(feature = "tls")]
use rustls::ClientSession;
#[cfg(feature = "tls")]
@@ -119,6 +121,25 @@ impl Read for Stream {
}
#[cfg(all(feature = "tls", not(feature = "native-tls")))]
pub(crate) trait ReclaimStream {
fn reclaim_stream(self) -> Stream;
}
impl ReclaimStream for Stream {
fn reclaim_stream(self) -> Stream {
self
}
}
impl<R: ReclaimStream> ReclaimStream for ChunkDecoder<R>
where
R: Read,
{
fn reclaim_stream(self) -> Stream {
self.into_inner().reclaim_stream()
}
}
fn read_https(
stream: &mut StreamOwned<ClientSession, TcpStream>,
buf: &mut [u8],