1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-10 17:29:36 +00:00
actix-web/actix-http/src/h2/mod.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2021-01-04 00:49:02 +00:00
//! HTTP/2 implementation.
use std::{
pin::Pin,
task::{Context, Poll},
};
2019-02-02 04:18:44 +00:00
2019-02-06 19:44:15 +00:00
use bytes::Bytes;
2021-01-04 00:49:02 +00:00
use futures_core::{ready, Stream};
2019-02-06 19:44:15 +00:00
use h2::RecvStream;
mod dispatcher;
2019-02-02 04:18:44 +00:00
mod service;
2019-03-07 06:56:34 +00:00
pub use self::dispatcher::Dispatcher;
2019-02-06 19:44:15 +00:00
pub use self::service::H2Service;
use crate::error::PayloadError;
2021-01-04 00:49:02 +00:00
/// HTTP/2 peer stream.
2019-02-06 19:44:15 +00:00
pub struct Payload {
2021-01-04 00:49:02 +00:00
stream: RecvStream,
2019-02-06 19:44:15 +00:00
}
impl Payload {
2021-01-04 00:49:02 +00:00
pub(crate) fn new(stream: RecvStream) -> Self {
Self { stream }
2019-02-06 19:44:15 +00:00
}
}
impl Stream for Payload {
type Item = Result<Bytes, PayloadError>;
2019-12-07 18:46:51 +00:00
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
2019-02-06 19:44:15 +00:00
2021-01-04 00:49:02 +00:00
match ready!(Pin::new(&mut this.stream).poll_data(cx)) {
Some(Ok(chunk)) => {
2019-02-06 19:44:15 +00:00
let len = chunk.len();
2021-01-04 00:49:02 +00:00
match this.stream.flow_control().release_capacity(len) {
Ok(()) => Poll::Ready(Some(Ok(chunk))),
Err(err) => Poll::Ready(Some(Err(err.into()))),
2019-02-06 19:44:15 +00:00
}
}
2021-01-04 00:49:02 +00:00
Some(Err(err)) => Poll::Ready(Some(Err(err.into()))),
None => Poll::Ready(None),
2019-02-06 19:44:15 +00:00
}
}
}