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 <actionstar619@yahoo.co.jp>
This commit is contained in:
parent
515fa81a77
commit
24aec9320c
|
@ -46,7 +46,7 @@ bytes = { version = "^1.0", optional = true }
|
||||||
futures = { version = "^0.3", optional = true }
|
futures = { version = "^0.3", optional = true }
|
||||||
http = { version = "0.2", optional = true }
|
http = { version = "0.2", optional = true }
|
||||||
hyper = { version = "^0.14", optional = true }
|
hyper = { version = "^0.14", optional = true }
|
||||||
axum-lib = { version = "^0.4", optional = true , package="axum"}
|
axum-lib = { version = "^0.5", optional = true , package="axum"}
|
||||||
http-body = { version = "^0.4", optional = true }
|
http-body = { version = "^0.4", optional = true }
|
||||||
poem-lib = { version = "=1.2.34", optional = true, package = "poem" }
|
poem-lib = { version = "=1.2.34", optional = true, package = "poem" }
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cloudevents-sdk = { path = "../..", features = ["axum"] }
|
cloudevents-sdk = { path = "../..", features = ["axum"] }
|
||||||
axum = "^0.4"
|
axum = "^0.5"
|
||||||
http = "^0.2"
|
http = "^0.2"
|
||||||
tokio = { version = "^1", features = ["full"] }
|
tokio = { version = "^1", features = ["full"] }
|
||||||
tracing = "^0.1"
|
tracing = "^0.1"
|
||||||
|
|
|
@ -21,22 +21,17 @@ where
|
||||||
type Rejection = (StatusCode, String);
|
type Rejection = (StatusCode, String);
|
||||||
|
|
||||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||||
let headers = req.headers().cloned().ok_or(0).map_err(|_| {
|
|
||||||
(
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
"unexpected empty headers".to_string(),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let req_body = req
|
let req_body = req
|
||||||
.take_body()
|
.take_body()
|
||||||
.ok_or(0)
|
.ok_or(0)
|
||||||
.map_err(|_| (StatusCode::BAD_REQUEST, "unexpected empty body".to_string()))?;
|
.map_err(|_| (StatusCode::BAD_REQUEST, "unexpected empty body".to_string()))?;
|
||||||
|
|
||||||
let buf = body::to_bytes(req_body)
|
let buf = body::to_bytes(req_body)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e.into())))?;
|
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e.into())))?
|
||||||
to_event(&headers, buf.to_vec()).map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e)))
|
.to_vec();
|
||||||
|
let headers = req.headers();
|
||||||
|
|
||||||
|
to_event(headers, buf).map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue