Skip to content

Commit bf7c0bb

Browse files
committed
feat(server): add service property to server::conn::Parts
This allows getting the original service back. Closes #1471
1 parent 45cf8c5 commit bf7c0bb

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/client/conn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ where
269269
{
270270
/// Return the inner IO object, and additional information.
271271
pub fn into_parts(self) -> Parts<T> {
272-
let (io, read_buf) = self.inner.into_inner();
272+
let (io, read_buf, _) = self.inner.into_inner();
273273
Parts {
274274
io: io,
275275
read_buf: read_buf,

src/proto/h1/dispatch.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait Dispatch {
2828

2929
pub struct Server<S: Service> {
3030
in_flight: Option<S::Future>,
31-
service: S,
31+
pub(crate) service: S,
3232
}
3333

3434
pub struct Client<B> {
@@ -62,8 +62,9 @@ where
6262
self.conn.disable_keep_alive()
6363
}
6464

65-
pub fn into_inner(self) -> (I, Bytes) {
66-
self.conn.into_inner()
65+
pub fn into_inner(self) -> (I, Bytes, D) {
66+
let (io, buf) = self.conn.into_inner();
67+
(io, buf, self.dispatch)
6768
}
6869

6970
/// The "Future" poll function. Runs this dispatcher until the

src/server/conn.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141
/// This allows taking apart a `Connection` at a later time, in order to
4242
/// reclaim the IO object, and additional related pieces.
4343
#[derive(Debug)]
44-
pub struct Parts<T> {
44+
pub struct Parts<T, S> {
4545
/// The original IO object used in the handshake.
4646
pub io: T,
4747
/// A buffer of bytes that have been read but not processed as HTTP.
@@ -53,6 +53,8 @@ pub struct Parts<T> {
5353
/// You will want to check for any existing bytes if you plan to continue
5454
/// communicating on the IO object.
5555
pub read_buf: Bytes,
56+
/// The `Service` used to serve this connection.
57+
pub service: S,
5658
_inner: (),
5759
}
5860

@@ -74,11 +76,12 @@ where S: Service<Request = Request, Response = Response<B>, Error = ::Error> + '
7476
/// This should only be called after `poll_without_shutdown` signals
7577
/// that the connection is "done". Otherwise, it may not have finished
7678
/// flushing all necessary HTTP bytes.
77-
pub fn into_parts(self) -> Parts<I> {
78-
let (io, read_buf) = self.conn.into_inner();
79+
pub fn into_parts(self) -> Parts<I, S> {
80+
let (io, read_buf, dispatch) = self.conn.into_inner();
7981
Parts {
8082
io: io,
8183
read_buf: read_buf,
84+
service: dispatch.service,
8285
_inner: (),
8386
}
8487
}

0 commit comments

Comments
 (0)