Skip to content

Commit

Permalink
feat(server): add service property to server::conn::Parts
Browse files Browse the repository at this point in the history
This allows getting the original service back.

Closes #1471
  • Loading branch information
seanmonstar committed Mar 22, 2018
1 parent 45cf8c5 commit bf7c0bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ where
{
/// Return the inner IO object, and additional information.
pub fn into_parts(self) -> Parts<T> {
let (io, read_buf) = self.inner.into_inner();
let (io, read_buf, _) = self.inner.into_inner();
Parts {
io: io,
read_buf: read_buf,
Expand Down
7 changes: 4 additions & 3 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait Dispatch {

pub struct Server<S: Service> {
in_flight: Option<S::Future>,
service: S,
pub(crate) service: S,
}

pub struct Client<B> {
Expand Down Expand Up @@ -62,8 +62,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
Expand Down
9 changes: 6 additions & 3 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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<T> {
pub struct Parts<T, S> {
/// The original IO object used in the handshake.
pub io: T,
/// A buffer of bytes that have been read but not processed as HTTP.
Expand All @@ -53,6 +53,8 @@ pub struct Parts<T> {
/// 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: (),
}

Expand All @@ -74,11 +76,12 @@ where S: Service<Request = Request, Response = Response<B>, Error = ::Error> + '
/// 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<I> {
let (io, read_buf) = self.conn.into_inner();
pub fn into_parts(self) -> Parts<I, S> {
let (io, read_buf, dispatch) = self.conn.into_inner();
Parts {
io: io,
read_buf: read_buf,
service: dispatch.service,
_inner: (),
}
}
Expand Down

0 comments on commit bf7c0bb

Please sign in to comment.