Skip to content

Commit

Permalink
fun
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Dec 15, 2023
1 parent 93f0b0f commit 0fd22ac
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/async_impl/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use futures_core::Stream;
use futures_util::stream::Peekable;
use http::HeaderMap;
use hyper::body::Body as HttpBody;
use hyper::body::Frame;

#[cfg(any(feature = "gzip", feature = "brotli", feature = "deflate"))]
use tokio_util::codec::{BytesCodec, FramedRead};
Expand Down Expand Up @@ -261,20 +262,13 @@ impl HttpBody for Decoder {
type Data = Bytes;
type Error = crate::Error;

fn poll_data(
fn poll_frame(
self: Pin<&mut Self>,
cx: &mut Context,
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
self.poll_next(cx)
}

fn poll_trailers(
self: Pin<&mut Self>,
_cx: &mut Context,
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
Poll::Ready(Ok(None))
}

fn size_hint(&self) -> http_body::SizeHint {
match self.inner {
Inner::PlainText(ref body) => HttpBody::size_hint(body),
Expand Down
106 changes: 105 additions & 1 deletion src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl<T: TlsInfoFactory> TlsInfoFactory for hyper_tls::MaybeHttpsStream<T> {
#[cfg(feature = "default-tls")]
impl<T> TlsInfoFactory for hyper_tls::TlsStream<T>
where
tokio_native_tls::AllowStd<T>: std::io::Read + std::io::Write,
native_tls_crate::TlsStream<tokio_native_tls::AllowStd<T>>: std::io::Read + std::io::Write,
{
fn tls_info(&self) -> Option<crate::tls::TlsInfo> {
let peer_certificate = self
Expand Down Expand Up @@ -697,6 +697,107 @@ fn tunnel_eof() -> BoxError {
"unexpected eof while tunneling".into()
}

/*
#[cfg(feature = "default-tls")]
mod native_tls_conn {
use super::TlsInfoFactory;
use hyper_util::client::legacy::connect::{Connected, Connection};
use hyper_util::rt::TokioIo;
use pin_project_lite::pin_project;
use std::{
io::{self, IoSlice},
pin::Pin,
task::{Context, Poll},
};
use hyper::rt::{Read, ReadBufCursor, Write};
use tokio_native_tls::TlsStream;
pin_project! {
pub(super) struct NativeTlsConn<T> {
#[pin] pub(super) inner: TokioIo<TlsStream<T>>,
}
}
impl<T: Connection + Read + Write + Unpin> Connection for NativeTlsConn<T> {
#[cfg(feature = "native-tls-alpn")]
fn connected(&self) -> Connected {
match self.inner.inner().get_ref().negotiated_alpn().ok() {
Some(Some(alpn_protocol)) if alpn_protocol == b"h2" => self
.inner
.get_ref()
.get_ref()
.get_ref()
.connected()
.negotiated_h2(),
_ => self.inner.inner().get_ref().get_ref().get_ref().connected(),
}
}
#[cfg(not(feature = "native-tls-alpn"))]
fn connected(&self) -> Connected {
self.inner.inner().get_ref().get_ref().get_ref().connected()
}
}
impl<T: Read + Write + Unpin> Read for NativeTlsConn<T> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: ReadBufCursor<'_>,
) -> Poll<tokio::io::Result<()>> {
let this = self.project();
Read::poll_read(this.inner, cx, buf)
}
}
impl<T: Read + Write + Unpin> Write for NativeTlsConn<T> {
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8],
) -> Poll<Result<usize, tokio::io::Error>> {
let this = self.project();
Write::poll_write(this.inner, cx, buf)
}
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, io::Error>> {
let this = self.project();
Write::poll_write_vectored(this.inner, cx, bufs)
}
fn is_write_vectored(&self) -> bool {
self.inner.is_write_vectored()
}
fn poll_flush(
self: Pin<&mut Self>,
cx: &mut Context,
) -> Poll<Result<(), tokio::io::Error>> {
let this = self.project();
Write::poll_flush(this.inner, cx)
}
fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context,
) -> Poll<Result<(), tokio::io::Error>> {
let this = self.project();
Write::poll_shutdown(this.inner, cx)
}
}
impl<T: TlsInfoFactory> TlsInfoFactory for NativeTlsConn<T> {
fn tls_info(&self) -> Option<crate::tls::TlsInfo> {
self.inner.tls_info()
}
}
}
*/

#[cfg(feature = "__rustls")]
mod rustls_tls_conn {
use super::TlsInfoFactory;
Expand Down Expand Up @@ -902,8 +1003,11 @@ mod verbose {
) -> Poll<std::io::Result<()>> {
match Pin::new(&mut self.inner).poll_read(cx, buf) {
Poll::Ready(Ok(())) => {
/*
log::trace!("{:08x} read: {:?}", self.id, Escape(buf.filled()));
Poll::Ready(Ok(()))
*/
todo!("verbose poll_read");
}
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
Poll::Pending => Poll::Pending,
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl Error {
matches!(self.inner.kind, Kind::Request)
}

/*
#[cfg(not(target_arch = "wasm32"))]
/// Returns true if the error is related to connect
pub fn is_connect(&self) -> bool {
Expand All @@ -138,6 +139,7 @@ impl Error {
false
}
*/

/// Returns true if the error is related to the request or response body
pub fn is_body(&self) -> bool {
Expand Down

0 comments on commit 0fd22ac

Please sign in to comment.