Skip to content

Commit ae83a69

Browse files
authored
Axum 0.4.0 (#168)
* axum 0.4.0 Signed-off-by: andrew webber (personal) <[email protected]>
1 parent ba798f3 commit ae83a69

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bytes = { version = "^1.0", optional = true }
4545
futures = { version = "^0.3", optional = true }
4646
http = { version = "0.2", optional = true }
4747
hyper = { version = "^0.14", optional = true }
48-
axum-lib = { version = "^0.2", optional = true, package = "axum" }
48+
axum-lib = { version = "^0.4", optional = true , package="axum"}
4949
http-body = { version = "^0.4", optional = true }
5050
poem-lib = { version = "=1.2.34", optional = true, package = "poem" }
5151

example-projects/axum-example/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
name = "axum-example"
33
version = "0.3.0"
44
authors = ["Andrew Webber <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
[dependencies]
88
cloudevents-sdk = { path = "../..", features = ["axum"] }
9-
axum = "^0.2"
9+
axum = "^0.4"
1010
http = "^0.2"
1111
tokio = { version = "^1", features = ["full"] }
1212
tracing = "^0.1"

example-projects/axum-example/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use axum::{
2-
handler::{get, post},
3-
routing::BoxRoute,
2+
routing::{get, post},
43
Router,
54
};
65
use cloudevents::Event;
76
use http::StatusCode;
87
use std::net::SocketAddr;
98
use tower_http::trace::TraceLayer;
109

11-
fn echo_app() -> Router<BoxRoute> {
10+
fn echo_app() -> Router {
1211
Router::new()
1312
.route("/", get(|| async { "hello from cloudevents server" }))
1413
.route(
@@ -19,7 +18,6 @@ fn echo_app() -> Router<BoxRoute> {
1918
}),
2019
)
2120
.layer(TraceLayer::new_for_http())
22-
.boxed()
2321
}
2422

2523
#[tokio::main]

src/binding/axum/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
//! ```
99
//! use axum_lib as axum;
1010
//! use axum::{
11-
//! handler::{get, post},
12-
//! routing::BoxRoute,
11+
//! routing::{get, post},
1312
//! Router,
1413
//! };
1514
//! use cloudevents::Event;
1615
//! use http::StatusCode;
1716
//!
18-
//! fn app() -> Router<BoxRoute> {
17+
//! fn app() -> Router {
1918
//! Router::new()
2019
//! .route("/", get(|| async { "hello from cloudevents server" }))
2120
//! .route(
@@ -25,7 +24,6 @@
2524
//! (StatusCode::OK, event)
2625
//! }),
2726
//! )
28-
//! .boxed()
2927
//! }
3028
//!
3129
//! ```
@@ -35,15 +33,14 @@
3533
//! ```
3634
//! use axum_lib as axum;
3735
//! use axum::{
38-
//! handler::{get, post},
39-
//! routing::BoxRoute,
36+
//! routing::{get, post},
4037
//! Router,
4138
//! };
4239
//! use cloudevents::{Event, EventBuilder, EventBuilderV10};
4340
//! use http::StatusCode;
4441
//! use serde_json::json;
4542
//!
46-
//! fn app() -> Router<BoxRoute> {
43+
//! fn app() -> Router {
4744
//! Router::new()
4845
//! .route("/", get(|| async { "hello from cloudevents server" }))
4946
//! .route(
@@ -70,7 +67,6 @@
7067
//! Ok::<Event, (StatusCode, String)>(event)
7168
//! }),
7269
//! )
73-
//! .boxed()
7470
//! }
7571
//!
7672
//! ```
@@ -85,9 +81,8 @@ mod tests {
8581

8682
use axum::{
8783
body::Body,
88-
handler::{get, post},
8984
http::{self, Request, StatusCode},
90-
routing::BoxRoute,
85+
routing::{get, post},
9186
Router,
9287
};
9388
use chrono::Utc;
@@ -96,7 +91,7 @@ mod tests {
9691

9792
use crate::Event;
9893

99-
fn echo_app() -> Router<BoxRoute> {
94+
fn echo_app() -> Router {
10095
Router::new()
10196
.route("/", get(|| async { "hello from cloudevents server" }))
10297
.route(
@@ -106,7 +101,6 @@ mod tests {
106101
(StatusCode::OK, event)
107102
}),
108103
)
109-
.boxed()
110104
}
111105

112106
#[tokio::test]

src/binding/axum/response.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
use axum_lib as axum;
22

3-
use axum::{body::Body, http::Response, response::IntoResponse};
3+
use axum::{
4+
body::{boxed, BoxBody},
5+
http::Response,
6+
response::IntoResponse,
7+
};
48
use http::{header, StatusCode};
9+
use hyper::body::Body;
510

611
use crate::binding::http::builder::adapter::to_response;
712
use crate::event::Event;
813

914
impl IntoResponse for Event {
10-
type Body = Body;
11-
type BodyError = <Self::Body as axum::body::HttpBody>::Error;
12-
13-
fn into_response(self) -> Response<Body> {
15+
fn into_response(self) -> Response<BoxBody> {
1416
match to_response(self) {
15-
Ok(resp) => resp,
17+
Ok(resp) => {
18+
let (parts, body) = resp.into_parts();
19+
Response::from_parts(parts, boxed(body))
20+
}
1621
Err(err) => Response::builder()
1722
.status(StatusCode::INTERNAL_SERVER_ERROR)
1823
.header(header::CONTENT_TYPE, "text/plain")
19-
.body(err.to_string().into())
24+
.body(boxed(Body::from(err.to_string())))
2025
.unwrap(),
2126
}
2227
}

0 commit comments

Comments
 (0)