Skip to content

Commit

Permalink
chore(proxy/http): replace hyper::Body with BoxBody
Browse files Browse the repository at this point in the history
`UpgradeResponseBody` currently wraps a `hyper::Body`. this type is
removed in hyper 1.0.

this commit replaces this with a generic `B`-typed body.

see #3479, which performs
the same change in `linkerd-http-upgrade`.

see linkerd/linkerd2#8733 for more information
on upgrading to hyper 1.0.

Signed-off-by: katelyn martin <[email protected]>
  • Loading branch information
cratelyn committed Dec 20, 2024
1 parent a1a5713 commit cc13c01
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions linkerd/proxy/http/src/orig_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ pub struct DowngradedH2Error(h2::Reason);

#[pin_project::pin_project]
#[derive(Debug, Default)]
pub struct UpgradeResponseBody {
inner: hyper::Body,
pub struct UpgradeResponseBody<B> {
#[pin]
inner: B,
}

/// Downgrades HTTP2 requests that were previousl upgraded to their original
Expand Down Expand Up @@ -197,8 +198,12 @@ fn test_downgrade_h2_error() {

// === impl UpgradeResponseBody ===

impl Body for UpgradeResponseBody {
type Data = bytes::Bytes;
impl<B> Body for UpgradeResponseBody<B>
where
B: Body + Unpin,
B::Error: std::error::Error + Send + Sync + 'static,
{
type Data = B::Data;
type Error = Error;

#[inline]
Expand All @@ -210,7 +215,8 @@ impl Body for UpgradeResponseBody {
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
Pin::new(self.project().inner)
self.project()
.inner
.poll_data(cx)
.map_err(downgrade_h2_error)
}
Expand All @@ -219,7 +225,8 @@ impl Body for UpgradeResponseBody {
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
Pin::new(self.project().inner)
self.project()
.inner
.poll_trailers(cx)
.map_err(downgrade_h2_error)
}
Expand Down

0 comments on commit cc13c01

Please sign in to comment.