2019-12-13 05:59:02 +01:00
|
|
|
//! HTTP/2 implementation
|
2019-11-15 10:54:11 +01:00
|
|
|
use std::pin::Pin;
|
|
|
|
use std::task::{Context, Poll};
|
2019-02-02 05:18:44 +01:00
|
|
|
|
2019-02-06 20:44:15 +01:00
|
|
|
use bytes::Bytes;
|
2019-12-13 06:24:57 +01:00
|
|
|
use futures_core::Stream;
|
2019-02-06 20:44:15 +01:00
|
|
|
use h2::RecvStream;
|
|
|
|
|
|
|
|
mod dispatcher;
|
2019-02-02 05:18:44 +01:00
|
|
|
mod service;
|
|
|
|
|
2019-03-07 07:56:34 +01:00
|
|
|
pub use self::dispatcher::Dispatcher;
|
2019-02-06 20:44:15 +01:00
|
|
|
pub use self::service::H2Service;
|
|
|
|
use crate::error::PayloadError;
|
|
|
|
|
|
|
|
/// H2 receive stream
|
|
|
|
pub struct Payload {
|
|
|
|
pl: RecvStream,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Payload {
|
|
|
|
pub(crate) fn new(pl: RecvStream) -> Self {
|
|
|
|
Self { pl }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Stream for Payload {
|
2019-11-15 10:54:11 +01:00
|
|
|
type Item = Result<Bytes, PayloadError>;
|
|
|
|
|
2019-12-07 19:46:51 +01:00
|
|
|
fn poll_next(
|
|
|
|
self: Pin<&mut Self>,
|
|
|
|
cx: &mut Context<'_>,
|
|
|
|
) -> Poll<Option<Self::Item>> {
|
2019-11-15 10:54:11 +01:00
|
|
|
let this = self.get_mut();
|
2019-02-06 20:44:15 +01:00
|
|
|
|
2019-11-15 10:54:11 +01:00
|
|
|
match Pin::new(&mut this.pl).poll_data(cx) {
|
|
|
|
Poll::Ready(Some(Ok(chunk))) => {
|
2019-02-06 20:44:15 +01:00
|
|
|
let len = chunk.len();
|
2019-12-05 18:35:43 +01:00
|
|
|
if let Err(err) = this.pl.flow_control().release_capacity(len) {
|
2019-11-15 10:54:11 +01:00
|
|
|
Poll::Ready(Some(Err(err.into())))
|
2019-02-06 20:44:15 +01:00
|
|
|
} else {
|
2019-11-15 10:54:11 +01:00
|
|
|
Poll::Ready(Some(Ok(chunk)))
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-15 10:54:11 +01:00
|
|
|
Poll::Ready(Some(Err(err))) => Poll::Ready(Some(Err(err.into()))),
|
|
|
|
Poll::Pending => Poll::Pending,
|
|
|
|
Poll::Ready(None) => Poll::Ready(None),
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|