Skip to content

Conversation

@seanmonstar
Copy link
Member

Currently still WIP.

This introduces new types that provide integration of hyper::client::conn with tower::Layer and tower::Service.

}

/// todo
pub struct Http2Layer<B> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should be generic over the executor here:

diff --git a/src/client/conn.rs b/src/client/conn.rs
index d510ec3..0ec767b 100644
--- a/src/client/conn.rs
+++ b/src/client/conn.rs
@@ -39,7 +39,7 @@ impl<B> Clone for Http1Layer<B> {
     fn clone(&self) -> Self {
         Self {
             builder: self.builder.clone(),
-            _body: self._body.clone(),
+            _body: self._body,
         }
     }
 }
@@ -101,49 +101,69 @@ impl<M: Clone, B> Clone for Http1Connect<M, B> {
         Self {
             inner: self.inner.clone(),
             builder: self.builder.clone(),
-            _body: self._body.clone(),
+            _body: self._body,
         }
     }
 }

 /// todo
-pub struct Http2Layer<B> {
+pub struct Http2Layer<B, E> {
+    builder: hyper::client::conn::http2::Builder<E>,
     _body: PhantomData<fn(B)>,
 }

 /// todo
-pub fn http2<B>() -> Http2Layer<B> {
-    Http2Layer { _body: PhantomData }
+pub fn http2<B, E>(executor: E) -> Http2Layer<B, E>
+where
+    E: Clone,
+{
+    Http2Layer {
+        builder: hyper::client::conn::http2::Builder::new(executor),
+        _body: PhantomData,
+    }
 }

-impl<M, B> tower_layer::Layer<M> for Http2Layer<B> {
-    type Service = Http2Connect<M, B>;
+impl<M, B, E> tower_layer::Layer<M> for Http2Layer<B, E>
+where
+    E: Clone,
+{
+    type Service = Http2Connect<M, B, E>;
     fn layer(&self, inner: M) -> Self::Service {
         Http2Connect {
             inner,
-            builder: hyper::client::conn::http2::Builder::new(crate::rt::TokioExecutor::new()),
+            builder: self.builder.clone(),
             _body: self._body,
         }
     }
 }

-impl<B> Clone for Http2Layer<B> {
+impl<B, E: Clone> Clone for Http2Layer<B, E> {
     fn clone(&self) -> Self {
         Self {
-            _body: self._body.clone(),
+            builder: self.builder.clone(),
+            _body: self._body,
+        }
+    }
+}
+
+impl<B, E> From<hyper::client::conn::http2::Builder<E>> for Http2Layer<B, E> {
+    fn from(builder: hyper::client::conn::http2::Builder<E>) -> Self {
+        Self {
+            builder,
+            _body: PhantomData,
         }
     }
 }

 /// todo
 #[derive(Debug)]
-pub struct Http2Connect<M, B> {
+pub struct Http2Connect<M, B, E> {
     inner: M,
-    builder: hyper::client::conn::http2::Builder<crate::rt::TokioExecutor>,
+    builder: hyper::client::conn::http2::Builder<E>,
     _body: PhantomData<fn(B)>,
 }

-impl<M, Dst, B> Service<Dst> for Http2Connect<M, B>
+impl<M, Dst, B, E> Service<Dst> for Http2Connect<M, B, E>
 where
     M: Service<Dst>,
     M::Future: Send + 'static,
@@ -152,6 +172,7 @@ where
     B: hyper::body::Body + Unpin + Send + 'static,
     B::Data: Send + 'static,
     B::Error: Into<BoxError>,
+    E: hyper::rt::bounds::Http2ClientConnExec<B, M::Response> + Unpin + Clone + Send + 'static,
 {
     type Response = Http2ClientService<B>;
     type Error = BoxError;
@@ -179,12 +200,12 @@ where
     }
 }

-impl<M: Clone, B> Clone for Http2Connect<M, B> {
+impl<M: Clone, B, E: Clone> Clone for Http2Connect<M, B, E> {
     fn clone(&self) -> Self {
         Self {
             inner: self.inner.clone(),
             builder: self.builder.clone(),
-            _body: self._body.clone(),
+            _body: self._body,
         }
     }
 }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea definitely, it was something I skipped initially but knew it'd be needed before merging.

fn clone(&self) -> Self {
Self {
builder: self.builder.clone(),
_body: self._body.clone(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to clone phantom data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of other cases of this elsewhere


fn call(&mut self, req: Request<B>) -> Self::Future {
let fut = self.tx.send_request(req);
Box::pin(async move { Ok(fut.await?) })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for here and http1 we can just do Box::pin(fut).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants