Skip to content

Commit

Permalink
Add support in arnold for incoming bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudy committed Mar 30, 2024
1 parent afb8872 commit 7c5596c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions arnold/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ static-assertions.workspace = true
[features]
default = []
docs = ["dep:hyper"]
incoming = ["dep:hyper"]
22 changes: 22 additions & 0 deletions arnold/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ impl From<Empty<Bytes>> for Body {
}
}

#[cfg(feature = "incoming")]
impl From<hyper::body::Incoming> for Body {
fn from(body: hyper::body::Incoming) -> Self {
Self {
inner: InnerBody::Incoming(body),
}
}
}

impl<E> From<UnsyncBoxBody<Bytes, E>> for Body
where
E: Into<BoxError> + 'static,
Expand All @@ -110,6 +119,9 @@ enum InnerBody {
Empty,
Full(#[pin] Full<Bytes>),
Boxed(#[pin] Pin<Box<dyn http_body::Body<Data = Bytes, Error = BoxError> + Send + 'static>>),

#[cfg(feature = "incoming")]
Incoming(#[pin] hyper::body::Incoming),
}

impl From<String> for InnerBody {
Expand Down Expand Up @@ -139,6 +151,10 @@ impl http_body::Body for Body {
InnerBodyProj::Boxed(body) => body
.poll_frame(cx)
.map(|opt| opt.map(|res| res.map_err(Into::into))),
#[cfg(feature = "incoming")]
InnerBodyProj::Incoming(body) => body
.poll_frame(cx)
.map(|opt| opt.map(|res| res.map_err(Into::into))),
}
}

Expand All @@ -147,6 +163,8 @@ impl http_body::Body for Body {
InnerBody::Empty => true,
InnerBody::Full(ref body) => body.is_end_stream(),
InnerBody::Boxed(ref body) => body.is_end_stream(),
#[cfg(feature = "incoming")]
InnerBody::Incoming(ref body) => body.is_end_stream(),
}
}

Expand All @@ -155,6 +173,8 @@ impl http_body::Body for Body {
InnerBody::Empty => http_body::SizeHint::with_exact(0),
InnerBody::Full(ref body) => body.size_hint(),
InnerBody::Boxed(ref body) => body.size_hint(),
#[cfg(feature = "incoming")]
InnerBody::Incoming(ref body) => body.size_hint(),
}
}
}
Expand All @@ -165,6 +185,8 @@ impl fmt::Debug for InnerBody {
InnerBody::Empty => f.debug_struct("Empty").finish(),
InnerBody::Full(_) => f.debug_struct("Full").finish(),
InnerBody::Boxed(_) => f.debug_struct("Boxed").finish(),
#[cfg(feature = "incoming")]
InnerBody::Incoming(_) => f.debug_struct("Incoming").finish(),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions hyperdrive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ braid = { path = "../braid" }
patron = { path = "../patron" }
platter = { path = "../platter" }
roomservice = { path = "../roomservice" }

[features]
default = []
incoming = ["arnold/incoming"]

0 comments on commit 7c5596c

Please sign in to comment.