From dc5462f198a846014178f77bcc8f79bb412b2933 Mon Sep 17 00:00:00 2001 From: "andrew webber (personal)" Date: Fri, 14 Jan 2022 16:02:18 +0100 Subject: [PATCH] axum 0.4.0 Signed-off-by: andrew webber (personal) --- Cargo.toml | 2 +- example-projects/axum-example/Cargo.toml | 2 +- src/binding/axum/mod.rs | 18 ++++++------------ src/binding/axum/response.rs | 19 ++++++++++++------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 295052a..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.3", 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 80f81e7..0eb0e04 100644 --- a/example-projects/axum-example/Cargo.toml +++ b/example-projects/axum-example/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] cloudevents-sdk = { path = "../..", features = ["axum"] } -axum = "^0.3" +axum = "^0.4" http = "^0.2" tokio = { version = "^1", features = ["full"] } tracing = "^0.1" 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(), } }