From 18c5f640e293c91e0316847ea3dd4e51ab749fae Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 22 Mar 2018 13:37:09 -0700 Subject: [PATCH] feat(server): add `service` property to `server::conn::Parts` This allows getting the original service back. Closes #1471 Cherry-pick of commit bf7c0bbf4f55fdf465407874b0b2d4bd748e6783 from the 0.11.x branch. --- src/client/conn.rs | 2 +- src/proto/h1/dispatch.rs | 7 ++++--- src/server/conn.rs | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/client/conn.rs b/src/client/conn.rs index 0a89f9039e..97689bb50e 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -354,7 +354,7 @@ where /// /// Only works for HTTP/1 connections. HTTP/2 connections will panic. pub fn into_parts(self) -> Parts { - let (io, read_buf) = match self.inner { + let (io, read_buf, _) = match self.inner { Either::A(h1) => h1.into_inner(), Either::B(_h2) => { panic!("http2 cannot into_inner"); diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index db2c471dac..8cd7665dbe 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -27,7 +27,7 @@ pub(crate) trait Dispatch { pub struct Server { in_flight: Option, - service: S, + pub(crate) service: S, } pub struct Client { @@ -58,8 +58,9 @@ where self.conn.disable_keep_alive() } - pub fn into_inner(self) -> (I, Bytes) { - self.conn.into_inner() + pub fn into_inner(self) -> (I, Bytes, D) { + let (io, buf) = self.conn.into_inner(); + (io, buf, self.dispatch) } /// The "Future" poll function. Runs this dispatcher until the diff --git a/src/server/conn.rs b/src/server/conn.rs index d607900a5e..e650ec8342 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -98,7 +98,7 @@ where /// This allows taking apart a `Connection` at a later time, in order to /// reclaim the IO object, and additional related pieces. #[derive(Debug)] -pub struct Parts { +pub struct Parts { /// The original IO object used in the handshake. pub io: T, /// A buffer of bytes that have been read but not processed as HTTP. @@ -110,6 +110,8 @@ pub struct Parts { /// You will want to check for any existing bytes if you plan to continue /// communicating on the IO object. pub read_buf: Bytes, + /// The `Service` used to serve this connection. + pub service: S, _inner: (), } @@ -335,8 +337,8 @@ where /// This should only be called after `poll_without_shutdown` signals /// that the connection is "done". Otherwise, it may not have finished /// flushing all necessary HTTP bytes. - pub fn into_parts(self) -> Parts { - let (io, read_buf) = match self.conn { + pub fn into_parts(self) -> Parts { + let (io, read_buf, dispatch) = match self.conn { Either::A(h1) => { h1.into_inner() }, @@ -347,6 +349,7 @@ where Parts { io: io, read_buf: read_buf, + service: dispatch.service, _inner: (), } }