Skip to content

Commit

Permalink
Support for axum bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudy committed Mar 30, 2024
1 parent 7c5596c commit 9b2d86c
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 4 deletions.
175 changes: 171 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bridge = { path = "./bridge" }
patron = { path = "./patron" }
pidfile = { path = "./pidfile" }

axum = "0.7"
bytes = "1"
camino = { version = "1", default-features = false }
dashmap = "5"
Expand Down
1 change: 1 addition & 0 deletions arnold/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = { workspace = true, optional = true }
bytes.workspace = true
http-body.workspace = true
http-body-util.workspace = true
Expand Down
23 changes: 23 additions & 0 deletions arnold/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ impl From<hyper::body::Incoming> for Body {
}
}

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

impl<E> From<UnsyncBoxBody<Bytes, E>> for Body
where
E: Into<BoxError> + 'static,
Expand All @@ -122,6 +131,9 @@ enum InnerBody {

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

#[cfg(feature = "axum")]
AxumBody(#[pin] axum::body::Body),
}

impl From<String> for InnerBody {
Expand Down Expand Up @@ -155,6 +167,11 @@ impl http_body::Body for Body {
InnerBodyProj::Incoming(body) => body
.poll_frame(cx)
.map(|opt| opt.map(|res| res.map_err(Into::into))),

#[cfg(feature = "axum")]
InnerBodyProj::AxumBody(body) => body
.poll_frame(cx)
.map(|opt| opt.map(|res| res.map_err(Into::into))),
}
}

Expand All @@ -165,6 +182,8 @@ impl http_body::Body for Body {
InnerBody::Boxed(ref body) => body.is_end_stream(),
#[cfg(feature = "incoming")]
InnerBody::Incoming(ref body) => body.is_end_stream(),
#[cfg(feature = "axum")]
InnerBody::AxumBody(ref body) => body.is_end_stream(),
}
}

Expand All @@ -175,6 +194,8 @@ impl http_body::Body for Body {
InnerBody::Boxed(ref body) => body.size_hint(),
#[cfg(feature = "incoming")]
InnerBody::Incoming(ref body) => body.size_hint(),
#[cfg(feature = "axum")]
InnerBody::AxumBody(ref body) => body.size_hint(),
}
}
}
Expand All @@ -187,6 +208,8 @@ impl fmt::Debug for InnerBody {
InnerBody::Boxed(_) => f.debug_struct("Boxed").finish(),
#[cfg(feature = "incoming")]
InnerBody::Incoming(_) => f.debug_struct("Incoming").finish(),
#[cfg(feature = "axum")]
InnerBody::AxumBody(_) => f.debug_struct("AxumBody").finish(),
}
}
}
Expand Down

0 comments on commit 9b2d86c

Please sign in to comment.