diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-17 20:46:23 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-17 20:46:23 +0100 |
commit | 143fe969eb6225c2aa8694930114103f1d4f0c9c (patch) | |
tree | 7f430400b464413fc16bd0bb91aad0436685482b /src/h3_support.rs | |
parent | a76cab9f30a51b9b4d2377b2d25640c129bf3ab3 (diff) | |
download | gnix-143fe969eb6225c2aa8694930114103f1d4f0c9c.tar gnix-143fe969eb6225c2aa8694930114103f1d4f0c9c.tar.bz2 gnix-143fe969eb6225c2aa8694930114103f1d4f0c9c.tar.zst |
h3 ground work
Diffstat (limited to 'src/h3_support.rs')
-rw-r--r-- | src/h3_support.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/h3_support.rs b/src/h3_support.rs new file mode 100644 index 0000000..56286db --- /dev/null +++ b/src/h3_support.rs @@ -0,0 +1,30 @@ +use crate::error::ServiceError; +use bytes::{Buf, Bytes}; +use h3::server::RequestStream; +use h3_quinn::RecvStream; +use hyper::body::{Body, Frame}; +use std::{ + pin::Pin, + task::{Context, Poll}, +}; + +pub struct H3RequestBody(pub RequestStream<RecvStream, Bytes>); + +impl Body for H3RequestBody { + type Data = Bytes; + type Error = ServiceError; + + fn poll_frame( + mut self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> { + match self.0.poll_recv_data(cx) { + Poll::Ready(Ok(Some(mut f))) => { + Poll::Ready(Some(Ok(Frame::data(f.copy_to_bytes(f.remaining()))))) + } + Poll::Ready(Ok(None)) => Poll::Ready(None), + Poll::Ready(Err(e)) => Poll::Ready(Some(Err(ServiceError::H3(e)))), + Poll::Pending => Poll::Pending, + } + } +} |