From 9b2d86c06fb3d7a3f1bbf20899523dfcb131e2f4 Mon Sep 17 00:00:00 2001 From: Alex Rudy Date: Sat, 30 Mar 2024 18:00:21 +0000 Subject: [PATCH] Support for axum bodies --- Cargo.lock | 175 ++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 1 + arnold/Cargo.toml | 1 + arnold/src/lib.rs | 23 ++++++ 4 files changed, 196 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 226f3a7..dae1bf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,6 +84,7 @@ dependencies = [ name = "arnold" version = "0.2.0" dependencies = [ + "axum", "bytes", "http", "http-body", @@ -93,6 +94,17 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "async-trait" +version = "0.1.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -125,6 +137,61 @@ dependencies = [ "paste", ] +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper 1.0.0", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -378,6 +445,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "fs_extra" version = "1.3.0" @@ -588,6 +664,22 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", +] + [[package]] name = "hyperdrive" version = "0.1.0" @@ -683,12 +775,24 @@ dependencies = [ "regex-automata 0.1.10", ] +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "memchr" version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -866,6 +970,12 @@ dependencies = [ "base64ct", ] +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pidfile" version = "0.1.0" @@ -1144,6 +1254,18 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + [[package]] name = "schannel" version = "0.1.23" @@ -1184,24 +1306,57 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.193" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", "syn 2.0.55", ] +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1297,6 +1452,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "sync_wrapper" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384595c11a4e2969895cad5a8c4029115f5ab956a9e5ef4de79d11a426e5f20c" + [[package]] name = "tempfile" version = "3.10.1" diff --git a/Cargo.toml b/Cargo.toml index 2e6bf4b..25c940c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/arnold/Cargo.toml b/arnold/Cargo.toml index f52f4fc..ebbb722 100644 --- a/arnold/Cargo.toml +++ b/arnold/Cargo.toml @@ -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 diff --git a/arnold/src/lib.rs b/arnold/src/lib.rs index f83a00a..dd1cd9e 100644 --- a/arnold/src/lib.rs +++ b/arnold/src/lib.rs @@ -103,6 +103,15 @@ impl From for Body { } } +#[cfg(feature = "axum")] +impl From for Body { + fn from(body: axum::body::Body) -> Self { + Self { + inner: InnerBody::AxumBody(body), + } + } +} + impl From> for Body where E: Into + 'static, @@ -122,6 +131,9 @@ enum InnerBody { #[cfg(feature = "incoming")] Incoming(#[pin] hyper::body::Incoming), + + #[cfg(feature = "axum")] + AxumBody(#[pin] axum::body::Body), } impl From for InnerBody { @@ -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))), } } @@ -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(), } } @@ -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(), } } } @@ -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(), } } }