diff --git a/Cargo.toml b/Cargo.toml index 94b54d9..c1ba1fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,11 +14,11 @@ edition = "2018" vendored = ["native-tls/vendored"] [dependencies] -bytes = "0.5" +bytes = "1.0" native-tls = "0.2" -hyper = { version = "0.13", default-features = false, features = ["tcp"] } -tokio = { version = "0.2" } -tokio-tls = "0.3" +hyper = { version = "0.14", default-features = false, features = ["tcp", "client", "http1"] } +tokio = { version = "1.0" } +tokio-native-tls = { git = "https://github.com/tokio-rs/tls.git" } [dev-dependencies] -tokio = { version = "0.2", features = ["io-std", "macros"] } +tokio = { version = "1.0", features = ["full"] } diff --git a/src/client.rs b/src/client.rs index a0cf624..1f4f8c2 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,7 +5,7 @@ use std::task::{Context, Poll}; use hyper::{client::connect::HttpConnector, service::Service, Uri}; use tokio::io::{AsyncRead, AsyncWrite}; -use tokio_tls::TlsConnector; +use tokio_native_tls::TlsConnector; use crate::stream::MaybeHttpsStream; diff --git a/src/stream.rs b/src/stream.rs index a924c2c..25f225f 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -3,10 +3,9 @@ use std::io; use std::pin::Pin; use std::task::{Context, Poll}; -use bytes::{Buf, BufMut}; use hyper::client::connect::{Connected, Connection}; -use tokio::io::{AsyncRead, AsyncWrite}; -pub use tokio_tls::TlsStream; +use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; +pub use tokio_native_tls::TlsStream; /// A stream that might be protected with TLS. pub enum MaybeHttpsStream { @@ -40,37 +39,17 @@ impl From> for MaybeHttpsStream { } impl AsyncRead for MaybeHttpsStream { - #[inline] - unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit]) -> bool { - match self { - MaybeHttpsStream::Http(s) => s.prepare_uninitialized_buffer(buf), - MaybeHttpsStream::Https(s) => s.prepare_uninitialized_buffer(buf), - } - } - #[inline] fn poll_read( self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut [u8], - ) -> Poll> { + cx: &mut Context<'_>, + buf: &mut ReadBuf<'_>, + ) -> Poll> { match Pin::get_mut(self) { MaybeHttpsStream::Http(s) => Pin::new(s).poll_read(cx, buf), MaybeHttpsStream::Https(s) => Pin::new(s).poll_read(cx, buf), } } - - #[inline] - fn poll_read_buf( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut B, - ) -> Poll> { - match Pin::get_mut(self) { - MaybeHttpsStream::Http(s) => Pin::new(s).poll_read_buf(cx, buf), - MaybeHttpsStream::Https(s) => Pin::new(s).poll_read_buf(cx, buf), - } - } } impl AsyncWrite for MaybeHttpsStream { @@ -87,14 +66,22 @@ impl AsyncWrite for MaybeHttpsStream { } #[inline] - fn poll_write_buf( + fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, - buf: &mut B, + bufs: &[io::IoSlice<'_>], ) -> Poll> { match Pin::get_mut(self) { - MaybeHttpsStream::Http(s) => Pin::new(s).poll_write_buf(cx, buf), - MaybeHttpsStream::Https(s) => Pin::new(s).poll_write_buf(cx, buf), + MaybeHttpsStream::Http(s) => Pin::new(s).poll_write_vectored(cx, bufs), + MaybeHttpsStream::Https(s) => Pin::new(s).poll_write_vectored(cx, bufs), + } + } + + #[inline] + fn is_write_vectored(&self) -> bool { + match self { + MaybeHttpsStream::Http(s) => s.is_write_vectored(), + MaybeHttpsStream::Https(s) => s.is_write_vectored(), } } @@ -119,7 +106,7 @@ impl Connection for MaybeHttpsSt fn connected(&self) -> Connected { match self { MaybeHttpsStream::Http(s) => s.connected(), - MaybeHttpsStream::Https(s) => s.get_ref().connected(), + MaybeHttpsStream::Https(s) => s.get_ref().get_ref().get_ref().connected(), } } }