Skip to content

Commit 24aec93

Browse files
authored
Support for Axum v0.5.x (#179)
* Support for Axum x0.5.x * Upgrade axum v0.5 for example-project Signed-off-by: Yoshiki Kudo <[email protected]>
1 parent 515fa81 commit 24aec93

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

Cargo.toml

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

example-projects/axum-example/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66

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

src/binding/axum/extract.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,17 @@ where
2121
type Rejection = (StatusCode, String);
2222

2323
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
24-
let headers = req.headers().cloned().ok_or(0).map_err(|_| {
25-
(
26-
StatusCode::BAD_REQUEST,
27-
"unexpected empty headers".to_string(),
28-
)
29-
})?;
30-
3124
let req_body = req
3225
.take_body()
3326
.ok_or(0)
3427
.map_err(|_| (StatusCode::BAD_REQUEST, "unexpected empty body".to_string()))?;
35-
3628
let buf = body::to_bytes(req_body)
3729
.await
38-
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e.into())))?;
39-
to_event(&headers, buf.to_vec()).map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e)))
30+
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e.into())))?
31+
.to_vec();
32+
let headers = req.headers();
33+
34+
to_event(headers, buf).map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e)))
4035
}
4136
}
4237

0 commit comments

Comments
 (0)