Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::body::{Body, Incoming as IncomingBody};
use crate::proto;

type Dispatcher<T, B> =
proto::dispatch::Dispatcher<proto::dispatch::Client<B>, B, T, proto::h1::ClientTransaction>;
proto::dispatch::Dispatcher<'static, proto::dispatch::Client<B>, B, T, proto::h1::ClientTransaction>;

/// The sender side of an established connection.
pub struct SendRequest<B> {
Expand Down
12 changes: 7 additions & 5 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ use crate::common::task;
use crate::proto::{BodyLength, Conn, Dispatched, MessageHead, RequestHead};
use crate::upgrade::OnUpgrade;

pub(crate) struct Dispatcher<D, Bs: Body, I, T> {
pub(crate) struct Dispatcher<'body, D, Bs: Body + 'body, I, T> {
conn: Conn<I, Bs::Data, T>,
dispatch: D,
body_tx: Option<crate::body::Sender>,
body_rx: Pin<Box<Option<Bs>>>,
is_closing: bool,
_a: std::marker::PhantomData<&'body ()>
}

pub(crate) trait Dispatch {
Expand Down Expand Up @@ -64,7 +65,7 @@ cfg_client! {
type ClientRx<B> = crate::client::dispatch::Receiver<Request<B>, http::Response<IncomingBody>>;
}

impl<D, Bs, I, T> Dispatcher<D, Bs, I, T>
impl<'body, D, Bs, I, T> Dispatcher<'body, D, Bs, I, T>
where
D: Dispatch<
PollItem = MessageHead<T::Outgoing>,
Expand All @@ -74,7 +75,7 @@ where
D::PollError: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
T: Http1Transaction + Unpin,
Bs: Body + 'static,
Bs: Body + 'body,
Bs::Error: Into<Box<dyn StdError + Send + Sync>>,
{
pub(crate) fn new(dispatch: D, conn: Conn<I, Bs::Data, T>) -> Self {
Expand All @@ -84,6 +85,7 @@ where
body_tx: None,
body_rx: Box::pin(None),
is_closing: false,
_a: Default::default()
}
}

Expand Down Expand Up @@ -451,7 +453,7 @@ where
}
}

impl<D, Bs, I, T> Future for Dispatcher<D, Bs, I, T>
impl<'body, D, Bs, I, T> Future for Dispatcher<'body, D, Bs, I, T>
where
D: Dispatch<
PollItem = MessageHead<T::Outgoing>,
Expand All @@ -461,7 +463,7 @@ where
D::PollError: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
T: Http1Transaction + Unpin,
Bs: Body + 'static,
Bs: Body + 'body,
Bs::Error: Into<Box<dyn StdError + Send + Sync>>,
{
type Output = crate::Result<Dispatched>;
Expand Down
18 changes: 10 additions & 8 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Default for Config {
}

pin_project! {
pub(crate) struct Server<T, S, B, E>
pub(crate) struct Server<'body, T, S, B, E>
where
S: HttpService<IncomingBody>,
B: Body,
Expand All @@ -88,7 +88,8 @@ pin_project! {
service: S,
state: State<T, B>,
date_header: bool,
close_pending: bool
close_pending: bool,
_v: std::marker::PhantomData<&'body ()>
}
}

Expand All @@ -113,12 +114,12 @@ where
date_header: bool,
}

impl<T, S, B, E> Server<T, S, B, E>
impl<'body, T, S, B, E> Server<'body, T, S, B, E>
where
T: Read + Write + Unpin,
S: HttpService<IncomingBody, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Body + 'static,
B: Body + 'body,
E: Http2ServerConnExec<S::Future, B>,
{
pub(crate) fn new(
Expand All @@ -127,7 +128,7 @@ where
config: &Config,
exec: E,
timer: Time,
) -> Server<T, S, B, E> {
) -> Server<'body, T, S, B, E> {
let mut builder = h2::server::Builder::default();
builder
.initial_window_size(config.initial_stream_window_size)
Expand Down Expand Up @@ -172,6 +173,7 @@ where
service,
date_header: config.date_header,
close_pending: false,
_v: Default::default()
}
}

Expand All @@ -190,12 +192,12 @@ where
}
}

impl<T, S, B, E> Future for Server<T, S, B, E>
impl<'body, T, S, B, E> Future for Server<'body, T, S, B, E>
where
T: Read + Write + Unpin,
S: HttpService<IncomingBody, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Body + 'static,
B: Body + 'body,
E: Http2ServerConnExec<S::Future, B>,
{
type Output = crate::Result<Dispatched>;
Expand Down Expand Up @@ -239,7 +241,7 @@ where
impl<T, B> Serving<T, B>
where
T: Read + Write + Unpin,
B: Body + 'static,
B: Body,
{
fn poll_server<S, E>(
&mut self,
Expand Down
45 changes: 23 additions & 22 deletions src/server/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use crate::{
rt::Timer,
};

type Http1Dispatcher<T, B, S> = proto::h1::Dispatcher<
type Http1Dispatcher<'body, T, B, S> = proto::h1::Dispatcher<
'body,
proto::h1::dispatch::Server<S, IncomingBody>,
B,
T,
Expand All @@ -36,11 +37,11 @@ pin_project_lite::pin_project! {
/// To drive HTTP on this connection this future **must be polled**, typically with
/// `.await`. If it isn't polled, no progress will be made on this connection.
#[must_use = "futures do nothing unless polled"]
pub struct Connection<T, S>
pub struct Connection<'body, T, S>
where
S: HttpService<IncomingBody>,
{
conn: Http1Dispatcher<T, S::ResBody, S>,
conn: Http1Dispatcher<'body, T, S::ResBody, S>,
}
}

Expand Down Expand Up @@ -107,7 +108,7 @@ pub struct Parts<T, S> {

// ===== impl Connection =====

impl<I, S> fmt::Debug for Connection<I, S>
impl<'body, I, S> fmt::Debug for Connection<'body, I, S>
where
S: HttpService<IncomingBody>,
{
Expand All @@ -116,12 +117,12 @@ where
}
}

impl<I, B, S> Connection<I, S>
impl<'body, I, B, S> Connection<'body, I, S>
where
S: HttpService<IncomingBody, ResBody = B>,
S: HttpService<IncomingBody, ResBody = B> + 'body,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
B: Body + 'static,
I: Read + Write + Unpin + 'body,
B: Body + 'body,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
/// Start a graceful shutdown process for this connection.
Expand Down Expand Up @@ -177,7 +178,7 @@ where
/// # Error
///
/// This errors if the underlying connection protocol is not HTTP/1.
pub fn without_shutdown(self) -> impl Future<Output = crate::Result<Parts<I, S>>> {
pub fn without_shutdown(self) -> impl Future<Output = crate::Result<Parts<I, S>>> + 'body {
let mut zelf = Some(self);
crate::common::future::poll_fn(move |cx| {
ready!(zelf.as_mut().unwrap().conn.poll_without_shutdown(cx))?;
Expand All @@ -188,20 +189,20 @@ where
/// Enable this connection to support higher-level HTTP upgrades.
///
/// See [the `upgrade` module](crate::upgrade) for more.
pub fn with_upgrades(self) -> UpgradeableConnection<I, S>
pub fn with_upgrades(self) -> UpgradeableConnection<'body, I, S>
where
I: Send,
{
UpgradeableConnection { inner: Some(self) }
}
}

impl<I, B, S> Future for Connection<I, S>
impl<'body, I, B, S> Future for Connection<'body, I, S>
where
S: HttpService<IncomingBody, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
B: Body + 'static,
B: Body + 'body,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
type Output = crate::Result<()>;
Expand Down Expand Up @@ -441,11 +442,11 @@ impl Builder {
/// # }
/// # fn main() {}
/// ```
pub fn serve_connection<I, S>(&self, io: I, service: S) -> Connection<I, S>
pub fn serve_connection<'body, I, S>(&self, io: I, service: S) -> Connection<'body, I, S>
where
S: HttpService<IncomingBody>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
S::ResBody: 'static,
S::ResBody: 'body,
<S::ResBody as Body>::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
{
Expand Down Expand Up @@ -496,19 +497,19 @@ impl Builder {
/// A future binding a connection with a Service with Upgrade support.
#[must_use = "futures do nothing unless polled"]
#[allow(missing_debug_implementations)]
pub struct UpgradeableConnection<T, S>
pub struct UpgradeableConnection<'body, T, S>
where
S: HttpService<IncomingBody>,
{
pub(super) inner: Option<Connection<T, S>>,
pub(super) inner: Option<Connection<'body, T, S>>,
}

impl<I, B, S> UpgradeableConnection<I, S>
impl<'body, I, B, S> UpgradeableConnection<'body, I, S>
where
S: HttpService<IncomingBody, ResBody = B>,
S: HttpService<IncomingBody, ResBody = B> + 'body,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
B: Body + 'static,
I: Read + Write + Unpin + 'body,
B: Body + 'body,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
/// Start a graceful shutdown process for this connection.
Expand All @@ -524,12 +525,12 @@ where
}
}

impl<I, B, S> Future for UpgradeableConnection<I, S>
impl<'body, I, B, S> Future for UpgradeableConnection<'body, I, S>
where
S: HttpService<IncomingBody, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin + Send + 'static,
B: Body + 'static,
B: Body + 'body,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
type Output = crate::Result<()>;
Expand Down
18 changes: 9 additions & 9 deletions src/server/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pin_project! {
/// To drive HTTP on this connection this future **must be polled**, typically with
/// `.await`. If it isn't polled, no progress will be made on this connection.
#[must_use = "futures do nothing unless polled"]
pub struct Connection<T, S, E>
pub struct Connection<'body, T, S, E>
where
S: HttpService<IncomingBody>,
{
conn: proto::h2::Server<T, S, S::ResBody, E>,
conn: proto::h2::Server<'body, T, S, S::ResBody, E>,
}
}

Expand All @@ -47,7 +47,7 @@ pub struct Builder<E> {

// ===== impl Connection =====

impl<I, S, E> fmt::Debug for Connection<I, S, E>
impl<'body, I, S, E> fmt::Debug for Connection<'body, I, S, E>
where
S: HttpService<IncomingBody>,
{
Expand All @@ -56,12 +56,12 @@ where
}
}

impl<I, B, S, E> Connection<I, S, E>
impl<'body, I, B, S, E> Connection<'body, I, S, E>
where
S: HttpService<IncomingBody, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
B: Body + 'static,
B: Body + 'body,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: Http2ServerConnExec<S::Future, B>,
{
Expand All @@ -80,12 +80,12 @@ where
}
}

impl<I, B, S, E> Future for Connection<I, S, E>
impl<'body, I, B, S, E> Future for Connection<'body, I, S, E>
where
S: HttpService<IncomingBody, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
B: Body + 'static,
B: Body + 'body,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: Http2ServerConnExec<S::Future, B>,
{
Expand Down Expand Up @@ -291,11 +291,11 @@ impl<E> Builder<E> {
///
/// This returns a Future that must be polled in order for HTTP to be
/// driven on the connection.
pub fn serve_connection<S, I, Bd>(&self, io: I, service: S) -> Connection<I, S, E>
pub fn serve_connection<'body, S, I, Bd>(&self, io: I, service: S) -> Connection<'body, I, S, E>
where
S: HttpService<IncomingBody, ResBody = Bd>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
Bd: Body + 'static,
Bd: Body + 'body,
Bd::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin,
E: Http2ServerConnExec<S::Future, Bd>,
Expand Down