Merge pull request #1507 from bluetech/cp-parts-service
Fix example & cherry-pick server::conn::Parts.service to master
This commit is contained in:
@@ -5,7 +5,7 @@ extern crate pretty_env_logger;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use hyper::{Body, Client, Request};
|
use hyper::Client;
|
||||||
use hyper::rt::{self, Future, Stream};
|
use hyper::rt::{self, Future, Stream};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ where
|
|||||||
///
|
///
|
||||||
/// Only works for HTTP/1 connections. HTTP/2 connections will panic.
|
/// Only works for HTTP/1 connections. HTTP/2 connections will panic.
|
||||||
pub fn into_parts(self) -> Parts<T> {
|
pub fn into_parts(self) -> Parts<T> {
|
||||||
let (io, read_buf) = match self.inner {
|
let (io, read_buf, _) = match self.inner {
|
||||||
Either::A(h1) => h1.into_inner(),
|
Either::A(h1) => h1.into_inner(),
|
||||||
Either::B(_h2) => {
|
Either::B(_h2) => {
|
||||||
panic!("http2 cannot into_inner");
|
panic!("http2 cannot into_inner");
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pub(crate) trait Dispatch {
|
|||||||
|
|
||||||
pub struct Server<S: Service> {
|
pub struct Server<S: Service> {
|
||||||
in_flight: Option<S::Future>,
|
in_flight: Option<S::Future>,
|
||||||
service: S,
|
pub(crate) service: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Client<B> {
|
pub struct Client<B> {
|
||||||
@@ -58,8 +58,9 @@ where
|
|||||||
self.conn.disable_keep_alive()
|
self.conn.disable_keep_alive()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_inner(self) -> (I, Bytes) {
|
pub fn into_inner(self) -> (I, Bytes, D) {
|
||||||
self.conn.into_inner()
|
let (io, buf) = self.conn.into_inner();
|
||||||
|
(io, buf, self.dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The "Future" poll function. Runs this dispatcher until the
|
/// The "Future" poll function. Runs this dispatcher until the
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ where
|
|||||||
/// This allows taking apart a `Connection` at a later time, in order to
|
/// This allows taking apart a `Connection` at a later time, in order to
|
||||||
/// reclaim the IO object, and additional related pieces.
|
/// reclaim the IO object, and additional related pieces.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Parts<T> {
|
pub struct Parts<T, S> {
|
||||||
/// The original IO object used in the handshake.
|
/// The original IO object used in the handshake.
|
||||||
pub io: T,
|
pub io: T,
|
||||||
/// A buffer of bytes that have been read but not processed as HTTP.
|
/// A buffer of bytes that have been read but not processed as HTTP.
|
||||||
@@ -110,6 +110,8 @@ pub struct Parts<T> {
|
|||||||
/// You will want to check for any existing bytes if you plan to continue
|
/// You will want to check for any existing bytes if you plan to continue
|
||||||
/// communicating on the IO object.
|
/// communicating on the IO object.
|
||||||
pub read_buf: Bytes,
|
pub read_buf: Bytes,
|
||||||
|
/// The `Service` used to serve this connection.
|
||||||
|
pub service: S,
|
||||||
_inner: (),
|
_inner: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,8 +337,8 @@ where
|
|||||||
/// This should only be called after `poll_without_shutdown` signals
|
/// This should only be called after `poll_without_shutdown` signals
|
||||||
/// that the connection is "done". Otherwise, it may not have finished
|
/// that the connection is "done". Otherwise, it may not have finished
|
||||||
/// flushing all necessary HTTP bytes.
|
/// flushing all necessary HTTP bytes.
|
||||||
pub fn into_parts(self) -> Parts<I> {
|
pub fn into_parts(self) -> Parts<I, S> {
|
||||||
let (io, read_buf) = match self.conn {
|
let (io, read_buf, dispatch) = match self.conn {
|
||||||
Either::A(h1) => {
|
Either::A(h1) => {
|
||||||
h1.into_inner()
|
h1.into_inner()
|
||||||
},
|
},
|
||||||
@@ -347,6 +349,7 @@ where
|
|||||||
Parts {
|
Parts {
|
||||||
io: io,
|
io: io,
|
||||||
read_buf: read_buf,
|
read_buf: read_buf,
|
||||||
|
service: dispatch.service,
|
||||||
_inner: (),
|
_inner: (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user