Skip to content

Commit ef14a1b

Browse files
authored
Merge pull request #1507 from bluetech/cp-parts-service
Fix example & cherry-pick server::conn::Parts.service to master
2 parents 7de3bc9 + 18c5f64 commit ef14a1b

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

examples/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate pretty_env_logger;
55
use std::env;
66
use std::io::{self, Write};
77

8-
use hyper::{Body, Client, Request};
8+
use hyper::Client;
99
use hyper::rt::{self, Future, Stream};
1010

1111
fn main() {

src/client/conn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ where
354354
///
355355
/// Only works for HTTP/1 connections. HTTP/2 connections will panic.
356356
pub fn into_parts(self) -> Parts<T> {
357-
let (io, read_buf) = match self.inner {
357+
let (io, read_buf, _) = match self.inner {
358358
Either::A(h1) => h1.into_inner(),
359359
Either::B(_h2) => {
360360
panic!("http2 cannot into_inner");

src/proto/h1/dispatch.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) trait Dispatch {
2727

2828
pub struct Server<S: Service> {
2929
in_flight: Option<S::Future>,
30-
service: S,
30+
pub(crate) service: S,
3131
}
3232

3333
pub struct Client<B> {
@@ -58,8 +58,9 @@ where
5858
self.conn.disable_keep_alive()
5959
}
6060

61-
pub fn into_inner(self) -> (I, Bytes) {
62-
self.conn.into_inner()
61+
pub fn into_inner(self) -> (I, Bytes, D) {
62+
let (io, buf) = self.conn.into_inner();
63+
(io, buf, self.dispatch)
6364
}
6465

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

src/server/conn.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ where
9898
/// This allows taking apart a `Connection` at a later time, in order to
9999
/// reclaim the IO object, and additional related pieces.
100100
#[derive(Debug)]
101-
pub struct Parts<T> {
101+
pub struct Parts<T, S> {
102102
/// The original IO object used in the handshake.
103103
pub io: T,
104104
/// A buffer of bytes that have been read but not processed as HTTP.
@@ -110,6 +110,8 @@ pub struct Parts<T> {
110110
/// You will want to check for any existing bytes if you plan to continue
111111
/// communicating on the IO object.
112112
pub read_buf: Bytes,
113+
/// The `Service` used to serve this connection.
114+
pub service: S,
113115
_inner: (),
114116
}
115117

@@ -335,8 +337,8 @@ where
335337
/// This should only be called after `poll_without_shutdown` signals
336338
/// that the connection is "done". Otherwise, it may not have finished
337339
/// flushing all necessary HTTP bytes.
338-
pub fn into_parts(self) -> Parts<I> {
339-
let (io, read_buf) = match self.conn {
340+
pub fn into_parts(self) -> Parts<I, S> {
341+
let (io, read_buf, dispatch) = match self.conn {
340342
Either::A(h1) => {
341343
h1.into_inner()
342344
},
@@ -347,6 +349,7 @@ where
347349
Parts {
348350
io: io,
349351
read_buf: read_buf,
352+
service: dispatch.service,
350353
_inner: (),
351354
}
352355
}

0 commit comments

Comments
 (0)