mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-20 18:23:41 +00:00
H3: change structure of Body
This commit is contained in:
committed by
Jean-Christophe BEGUE
parent
74d8798b5d
commit
8a97c8d397
+5
-10
@@ -39,28 +39,23 @@ use crate::{
|
||||
///
|
||||
/// [`http::Request<B>`]: https://docs.rs/http/*/http/request/index.html
|
||||
/// [`http::Response<B>`]: https://docs.rs/http/*/http/response/index.html
|
||||
pub enum Body {
|
||||
/// Inexistent body
|
||||
None,
|
||||
/// Buffer-contained body
|
||||
Buf(Bytes),
|
||||
}
|
||||
pub struct Body(pub(crate) Option<Bytes>);
|
||||
|
||||
impl From<()> for Body {
|
||||
fn from(_: ()) -> Self {
|
||||
Body::None
|
||||
Body(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Bytes> for Body {
|
||||
fn from(buf: Bytes) -> Self {
|
||||
Body::Buf(buf)
|
||||
Body(Some(buf))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Body {
|
||||
fn from(buf: &str) -> Self {
|
||||
Body::Buf(Bytes::copy_from_slice(buf.as_ref()))
|
||||
Body(Some(Bytes::copy_from_slice(buf.as_ref())))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +355,7 @@ impl BodyWriter {
|
||||
/// let mut trailers = HeaderMap::new();
|
||||
/// trailers.insert("trailing", "here".parse()?);
|
||||
/// body_writer.trailers(trailers).await?;
|
||||
///
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@@ -450,7 +450,7 @@ impl Connection {
|
||||
/// let (response, mut body_reader) = recv_response.await?;
|
||||
/// let mut body = String::new();
|
||||
/// body_reader.read_to_string(&mut body).await?;
|
||||
///
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
@@ -512,14 +512,14 @@ impl Connection {
|
||||
|
||||
let recv = RecvResponse::new(FrameDecoder::stream(recv), self.0.clone(), stream_id);
|
||||
match body.into() {
|
||||
Body::Buf(payload) => {
|
||||
Body(Some(payload)) => {
|
||||
let send: WriteFrame<DataFrame<_>> = WriteFrame::new(send, DataFrame { payload });
|
||||
Ok((
|
||||
recv,
|
||||
BodyWriter::new(send.await?, self.0.clone(), stream_id, false),
|
||||
))
|
||||
}
|
||||
Body::None => Ok((
|
||||
Body(None) => Ok((
|
||||
recv,
|
||||
BodyWriter::new(send, self.0.clone(), stream_id, false),
|
||||
)),
|
||||
|
||||
@@ -785,8 +785,8 @@ impl Sender {
|
||||
)?
|
||||
.await?;
|
||||
let send = match body.into() {
|
||||
Body::None => send,
|
||||
Body::Buf(payload) => WriteFrame::new(send, DataFrame { payload }).await?,
|
||||
Body(None) => send,
|
||||
Body(Some(payload)) => WriteFrame::new(send, DataFrame { payload }).await?,
|
||||
};
|
||||
Ok(BodyWriter::new(send, self.conn, self.stream_id, true))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user