/rust/registry/src/index.crates.io-6f17d22bba15001f/hyper-rustls-0.27.5/src/stream.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Copied from hyperium/hyper-tls#62e3376/src/stream.rs |
2 | | use std::fmt; |
3 | | use std::io; |
4 | | use std::pin::Pin; |
5 | | use std::task::{Context, Poll}; |
6 | | |
7 | | use hyper::rt; |
8 | | use hyper_util::client::legacy::connect::{Connected, Connection}; |
9 | | |
10 | | use hyper_util::rt::TokioIo; |
11 | | use tokio_rustls::client::TlsStream; |
12 | | |
13 | | /// A stream that might be protected with TLS. |
14 | | #[allow(clippy::large_enum_variant)] |
15 | | pub enum MaybeHttpsStream<T> { |
16 | | /// A stream over plain text. |
17 | | Http(T), |
18 | | /// A stream protected with TLS. |
19 | | Https(TokioIo<TlsStream<TokioIo<T>>>), |
20 | | } |
21 | | |
22 | | impl<T: rt::Read + rt::Write + Connection + Unpin> Connection for MaybeHttpsStream<T> { |
23 | 0 | fn connected(&self) -> Connected { |
24 | 0 | match self { |
25 | 0 | Self::Http(s) => s.connected(), |
26 | 0 | Self::Https(s) => { |
27 | 0 | let (tcp, tls) = s.inner().get_ref(); |
28 | 0 | if tls.alpn_protocol() == Some(b"h2") { |
29 | 0 | tcp.inner().connected().negotiated_h2() |
30 | | } else { |
31 | 0 | tcp.inner().connected() |
32 | | } |
33 | | } |
34 | | } |
35 | 0 | } Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<hyper_util::rt::tokio::TokioIo<tokio::net::tcp::stream::TcpStream>> as hyper_util::client::legacy::connect::Connection>::connected Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<_> as hyper_util::client::legacy::connect::Connection>::connected |
36 | | } |
37 | | |
38 | | impl<T: fmt::Debug> fmt::Debug for MaybeHttpsStream<T> { |
39 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
40 | 0 | match *self { |
41 | 0 | Self::Http(..) => f.pad("Http(..)"), |
42 | 0 | Self::Https(..) => f.pad("Https(..)"), |
43 | | } |
44 | 0 | } |
45 | | } |
46 | | |
47 | | impl<T> From<T> for MaybeHttpsStream<T> { |
48 | 0 | fn from(inner: T) -> Self { |
49 | 0 | Self::Http(inner) |
50 | 0 | } |
51 | | } |
52 | | |
53 | | impl<T> From<TlsStream<TokioIo<T>>> for MaybeHttpsStream<T> { |
54 | 0 | fn from(inner: TlsStream<TokioIo<T>>) -> Self { |
55 | 0 | Self::Https(TokioIo::new(inner)) |
56 | 0 | } |
57 | | } |
58 | | |
59 | | impl<T: rt::Read + rt::Write + Unpin> rt::Read for MaybeHttpsStream<T> { |
60 | | #[inline] |
61 | 0 | fn poll_read( |
62 | 0 | self: Pin<&mut Self>, |
63 | 0 | cx: &mut Context, |
64 | 0 | buf: rt::ReadBufCursor<'_>, |
65 | 0 | ) -> Poll<Result<(), io::Error>> { |
66 | 0 | match Pin::get_mut(self) { |
67 | 0 | Self::Http(s) => Pin::new(s).poll_read(cx, buf), |
68 | 0 | Self::Https(s) => Pin::new(s).poll_read(cx, buf), |
69 | | } |
70 | 0 | } Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<hyper_util::rt::tokio::TokioIo<tokio::net::tcp::stream::TcpStream>> as hyper::rt::io::Read>::poll_read Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<_> as hyper::rt::io::Read>::poll_read |
71 | | } |
72 | | |
73 | | impl<T: rt::Write + rt::Read + Unpin> rt::Write for MaybeHttpsStream<T> { |
74 | | #[inline] |
75 | 0 | fn poll_write( |
76 | 0 | self: Pin<&mut Self>, |
77 | 0 | cx: &mut Context<'_>, |
78 | 0 | buf: &[u8], |
79 | 0 | ) -> Poll<Result<usize, io::Error>> { |
80 | 0 | match Pin::get_mut(self) { |
81 | 0 | Self::Http(s) => Pin::new(s).poll_write(cx, buf), |
82 | 0 | Self::Https(s) => Pin::new(s).poll_write(cx, buf), |
83 | | } |
84 | 0 | } Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<hyper_util::rt::tokio::TokioIo<tokio::net::tcp::stream::TcpStream>> as hyper::rt::io::Write>::poll_write Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<_> as hyper::rt::io::Write>::poll_write |
85 | | |
86 | | #[inline] |
87 | 0 | fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> { |
88 | 0 | match Pin::get_mut(self) { |
89 | 0 | Self::Http(s) => Pin::new(s).poll_flush(cx), |
90 | 0 | Self::Https(s) => Pin::new(s).poll_flush(cx), |
91 | | } |
92 | 0 | } Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<hyper_util::rt::tokio::TokioIo<tokio::net::tcp::stream::TcpStream>> as hyper::rt::io::Write>::poll_flush Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<_> as hyper::rt::io::Write>::poll_flush |
93 | | |
94 | | #[inline] |
95 | 0 | fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> { |
96 | 0 | match Pin::get_mut(self) { |
97 | 0 | Self::Http(s) => Pin::new(s).poll_shutdown(cx), |
98 | 0 | Self::Https(s) => Pin::new(s).poll_shutdown(cx), |
99 | | } |
100 | 0 | } Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<hyper_util::rt::tokio::TokioIo<tokio::net::tcp::stream::TcpStream>> as hyper::rt::io::Write>::poll_shutdown Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<_> as hyper::rt::io::Write>::poll_shutdown |
101 | | |
102 | | #[inline] |
103 | 0 | fn is_write_vectored(&self) -> bool { |
104 | 0 | match self { |
105 | 0 | Self::Http(s) => s.is_write_vectored(), |
106 | 0 | Self::Https(s) => s.is_write_vectored(), |
107 | | } |
108 | 0 | } Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<hyper_util::rt::tokio::TokioIo<tokio::net::tcp::stream::TcpStream>> as hyper::rt::io::Write>::is_write_vectored Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<_> as hyper::rt::io::Write>::is_write_vectored |
109 | | |
110 | | #[inline] |
111 | 0 | fn poll_write_vectored( |
112 | 0 | self: Pin<&mut Self>, |
113 | 0 | cx: &mut Context<'_>, |
114 | 0 | bufs: &[io::IoSlice<'_>], |
115 | 0 | ) -> Poll<Result<usize, io::Error>> { |
116 | 0 | match Pin::get_mut(self) { |
117 | 0 | Self::Http(s) => Pin::new(s).poll_write_vectored(cx, bufs), |
118 | 0 | Self::Https(s) => Pin::new(s).poll_write_vectored(cx, bufs), |
119 | | } |
120 | 0 | } Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<hyper_util::rt::tokio::TokioIo<tokio::net::tcp::stream::TcpStream>> as hyper::rt::io::Write>::poll_write_vectored Unexecuted instantiation: <hyper_rustls::stream::MaybeHttpsStream<_> as hyper::rt::io::Write>::poll_write_vectored |
121 | | } |