Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
goatgoose committed Jun 25, 2024
1 parent 989fd85 commit b729f0b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
47 changes: 22 additions & 25 deletions bindings/rust/s2n-tls-hyper/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ use tower_service::Service;
/// which sends and receives requests over TCP. The `HttpsConnector` struct wraps an HTTP connector,
/// and uses it to negotiate TLS when the HTTPS scheme is in use.
#[derive(Clone)]
pub struct HttpsConnector<T, B = Config>
where
B: connection::Builder,
<B as connection::Builder>::Output: Unpin,
{
http: T,
conn_builder: B,
pub struct HttpsConnector<Http, Builder = Config> {
http: Http,
conn_builder: Builder,
}

impl<B> HttpsConnector<HttpConnector, B>
impl<Builder> HttpsConnector<HttpConnector, Builder>
where
B: connection::Builder,
<B as connection::Builder>::Output: Unpin,
Builder: connection::Builder,
<Builder as connection::Builder>::Output: Unpin,
{
/// Creates a new `HttpsConnector`.
///
Expand All @@ -45,7 +41,7 @@ where
///
/// This API creates an `HttpsConnector` using the default hyper `HttpConnector`. To use an
/// existing HTTP connector, use `HttpsConnector::new_with_http()`.
pub fn new(conn_builder: B) -> HttpsConnector<HttpConnector, B> {
pub fn new(conn_builder: Builder) -> HttpsConnector<HttpConnector, Builder> {
let mut http = HttpConnector::new();

// By default, the `HttpConnector` only allows the HTTP URI scheme to be used. To negotiate
Expand All @@ -56,10 +52,10 @@ where
}
}

impl<T, B> HttpsConnector<T, B>
impl<Http, Builder> HttpsConnector<Http, Builder>
where
B: connection::Builder,
<B as connection::Builder>::Output: Unpin,
Builder: connection::Builder,
<Builder as connection::Builder>::Output: Unpin,
{
/// Creates a new `HttpsConnector`.
///
Expand All @@ -81,7 +77,7 @@ where
/// ```
///
/// `HttpsConnector::new()` can be used to create the HTTP connector automatically.
pub fn new_with_http(http: T, conn_builder: B) -> HttpsConnector<T, B> {
pub fn new_with_http(http: Http, conn_builder: Builder) -> HttpsConnector<Http, Builder> {
Self { http, conn_builder }
}
}
Expand All @@ -92,19 +88,20 @@ where
// https://docs.rs/hyper-util/latest/hyper_util/client/legacy/connect/trait.Connect.html
//
// The hyper compatibility traits for `Service::Response` are implemented in `MaybeHttpsStream`.
impl<T, B> Service<Uri> for HttpsConnector<T, B>
impl<Http, Builder> Service<Uri> for HttpsConnector<Http, Builder>
where
T: Service<Uri>,
T::Response: Read + Write + Connection + Unpin + Send + 'static,
T::Future: Send + 'static,
T::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
B: connection::Builder + Send + Sync + 'static,
<B as connection::Builder>::Output: Unpin + Send,
Http: Service<Uri>,
Http::Response: Read + Write + Connection + Unpin + Send + 'static,
Http::Future: Send + 'static,
Http::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
Builder: connection::Builder + Send + Sync + 'static,
<Builder as connection::Builder>::Output: Unpin + Send,
{
type Response = MaybeHttpsStream<T::Response, B>;
type Response = MaybeHttpsStream<Http::Response, Builder>;
type Error = Error;
type Future =
Pin<Box<dyn Future<Output = Result<MaybeHttpsStream<T::Response, B>, Error>> + Send>>;
type Future = Pin<
Box<dyn Future<Output = Result<MaybeHttpsStream<Http::Response, Builder>, Error>> + Send>,
>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match self.http.poll_ready(cx) {
Expand Down
42 changes: 21 additions & 21 deletions bindings/rust/s2n-tls-hyper/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@

use hyper::rt::{Read, ReadBufCursor, Write};
use hyper_util::{
client::legacy::connect::{Connected, Connection},
client::legacy::connect::{Connected, Connection as HyperConnection},
rt::TokioIo,
};
use s2n_tls::connection::Builder;
use s2n_tls::connection;
use s2n_tls_tokio::TlsStream;
use std::{
io::Error,
pin::Pin,
task::{Context, Poll},
};

/// `MaybeHttpsStream` is a wrapper over a hyper TCP stream, T, allowing for TLS to be negotiated
/// over the TCP stream.
/// `MaybeHttpsStream` is a wrapper over a hyper TCP stream, `Transport`, allowing for TLS to be
/// negotiated over the TCP stream.
///
/// While not currently implemented, the `MaybeHttpsStream` enum will provide an `Http` type
/// corresponding to the plain TCP stream, allowing for HTTP to be negotiated in addition to HTTPS
/// when the HTTP scheme is used.
///
/// This struct is used to implement `tower_service::Service` for `HttpsConnector`, and shouldn't
/// need to be used directly.
pub enum MaybeHttpsStream<T, B>
pub enum MaybeHttpsStream<Transport, Builder>
where
T: Read + Write + Unpin,
B: Builder,
<B as Builder>::Output: Unpin,
Transport: Read + Write + Unpin,
Builder: connection::Builder,
<Builder as connection::Builder>::Output: Unpin,
{
// T is the underlying hyper TCP stream, which is wrapped in a `TokioIo` type in order to make
// it compatible with tokio (implementing AsyncRead and AsyncWrite). This allows the TCP stream
Expand All @@ -37,14 +37,14 @@ where
// wrapped in an additional `TokioIo` type, which already implements the conversion from hyper's
// traits to tokio's. This allows the `Read` and `Write` implementations for `MaybeHttpsStream`
// to simply call the `TokioIo` `poll` functions.
Https(TokioIo<TlsStream<TokioIo<T>, B::Output>>),
Https(TokioIo<TlsStream<TokioIo<Transport>, Builder::Output>>),
}

impl<T, B> Connection for MaybeHttpsStream<T, B>
impl<Transport, Builder> HyperConnection for MaybeHttpsStream<Transport, Builder>
where
T: Read + Write + Connection + Unpin,
B: Builder,
<B as Builder>::Output: Unpin,
Transport: Read + Write + HyperConnection + Unpin,
Builder: connection::Builder,
<Builder as connection::Builder>::Output: Unpin,
{
fn connected(&self) -> Connected {
match self {
Expand All @@ -53,11 +53,11 @@ where
}
}

impl<T, B> Read for MaybeHttpsStream<T, B>
impl<Transport, Builder> Read for MaybeHttpsStream<Transport, Builder>
where
T: Read + Write + Unpin,
B: Builder,
<B as Builder>::Output: Unpin,
Transport: Read + Write + Unpin,
Builder: connection::Builder,
<Builder as connection::Builder>::Output: Unpin,
{
fn poll_read(
self: Pin<&mut Self>,
Expand All @@ -70,11 +70,11 @@ where
}
}

impl<T, B> Write for MaybeHttpsStream<T, B>
impl<Transport, Builder> Write for MaybeHttpsStream<Transport, Builder>
where
T: Read + Write + Unpin,
B: Builder,
<B as Builder>::Output: Unpin,
Transport: Read + Write + Unpin,
Builder: connection::Builder,
<Builder as connection::Builder>::Output: Unpin,
{
fn poll_write(
self: Pin<&mut Self>,
Expand Down

0 comments on commit b729f0b

Please sign in to comment.