diff --git a/Cargo.toml b/Cargo.toml index 402ff6d..3723f5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ bytes = { version = "^1.0", optional = true } futures = { version = "^0.3", optional = true } http = { version = "0.2", optional = true } hyper = { version = "^0.14", optional = true } -axum-lib = { version = "^0.2", optional = true, package = "axum" } +axum-lib = { version = "^0.4", optional = true , package="axum"} http-body = { version = "^0.4", optional = true } poem-lib = { version = "=1.2.34", optional = true, package = "poem" } diff --git a/example-projects/axum-example/Cargo.toml b/example-projects/axum-example/Cargo.toml index cb6cc09..0eb0e04 100644 --- a/example-projects/axum-example/Cargo.toml +++ b/example-projects/axum-example/Cargo.toml @@ -2,11 +2,11 @@ name = "axum-example" version = "0.3.0" authors = ["Andrew Webber "] -edition = "2018" +edition = "2021" [dependencies] cloudevents-sdk = { path = "../..", features = ["axum"] } -axum = "^0.2" +axum = "^0.4" http = "^0.2" tokio = { version = "^1", features = ["full"] } tracing = "^0.1" diff --git a/example-projects/axum-example/src/main.rs b/example-projects/axum-example/src/main.rs index 8caaec2..27a7b9a 100644 --- a/example-projects/axum-example/src/main.rs +++ b/example-projects/axum-example/src/main.rs @@ -1,6 +1,5 @@ use axum::{ - handler::{get, post}, - routing::BoxRoute, + routing::{get, post}, Router, }; use cloudevents::Event; @@ -8,7 +7,7 @@ use http::StatusCode; use std::net::SocketAddr; use tower_http::trace::TraceLayer; -fn echo_app() -> Router { +fn echo_app() -> Router { Router::new() .route("/", get(|| async { "hello from cloudevents server" })) .route( @@ -19,7 +18,6 @@ fn echo_app() -> Router { }), ) .layer(TraceLayer::new_for_http()) - .boxed() } #[tokio::main] diff --git a/src/binding/axum/mod.rs b/src/binding/axum/mod.rs index ad695d3..cb7b8a3 100644 --- a/src/binding/axum/mod.rs +++ b/src/binding/axum/mod.rs @@ -8,14 +8,13 @@ //! ``` //! use axum_lib as axum; //! use axum::{ -//! handler::{get, post}, -//! routing::BoxRoute, +//! routing::{get, post}, //! Router, //! }; //! use cloudevents::Event; //! use http::StatusCode; //! -//! fn app() -> Router { +//! fn app() -> Router { //! Router::new() //! .route("/", get(|| async { "hello from cloudevents server" })) //! .route( @@ -25,7 +24,6 @@ //! (StatusCode::OK, event) //! }), //! ) -//! .boxed() //! } //! //! ``` @@ -35,15 +33,14 @@ //! ``` //! use axum_lib as axum; //! use axum::{ -//! handler::{get, post}, -//! routing::BoxRoute, +//! routing::{get, post}, //! Router, //! }; //! use cloudevents::{Event, EventBuilder, EventBuilderV10}; //! use http::StatusCode; //! use serde_json::json; //! -//! fn app() -> Router { +//! fn app() -> Router { //! Router::new() //! .route("/", get(|| async { "hello from cloudevents server" })) //! .route( @@ -70,7 +67,6 @@ //! Ok::(event) //! }), //! ) -//! .boxed() //! } //! //! ``` @@ -85,9 +81,8 @@ mod tests { use axum::{ body::Body, - handler::{get, post}, http::{self, Request, StatusCode}, - routing::BoxRoute, + routing::{get, post}, Router, }; use chrono::Utc; @@ -96,7 +91,7 @@ mod tests { use crate::Event; - fn echo_app() -> Router { + fn echo_app() -> Router { Router::new() .route("/", get(|| async { "hello from cloudevents server" })) .route( @@ -106,7 +101,6 @@ mod tests { (StatusCode::OK, event) }), ) - .boxed() } #[tokio::test] diff --git a/src/binding/axum/response.rs b/src/binding/axum/response.rs index 0054534..3f4b956 100644 --- a/src/binding/axum/response.rs +++ b/src/binding/axum/response.rs @@ -1,22 +1,27 @@ use axum_lib as axum; -use axum::{body::Body, http::Response, response::IntoResponse}; +use axum::{ + body::{boxed, BoxBody}, + http::Response, + response::IntoResponse, +}; use http::{header, StatusCode}; +use hyper::body::Body; use crate::binding::http::builder::adapter::to_response; use crate::event::Event; impl IntoResponse for Event { - type Body = Body; - type BodyError = ::Error; - - fn into_response(self) -> Response { + fn into_response(self) -> Response { match to_response(self) { - Ok(resp) => resp, + Ok(resp) => { + let (parts, body) = resp.into_parts(); + Response::from_parts(parts, boxed(body)) + } Err(err) => Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .header(header::CONTENT_TYPE, "text/plain") - .body(err.to_string().into()) + .body(boxed(Body::from(err.to_string()))) .unwrap(), } }