axum 0.4.0

Signed-off-by: andrew webber (personal) <andrewvwebber@googlemail.com>
This commit is contained in:
andrew webber (personal) 2022-01-14 16:02:18 +01:00
parent 0dad41c4c6
commit dc5462f198
No known key found for this signature in database
GPG Key ID: B976107BE2AD4C18
4 changed files with 20 additions and 21 deletions

View File

@ -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" }

View File

@ -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"

View File

@ -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<BoxRoute> {
//! 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<BoxRoute> {
//! fn app() -> Router {
//! Router::new()
//! .route("/", get(|| async { "hello from cloudevents server" }))
//! .route(
@ -70,7 +67,6 @@
//! Ok::<Event, (StatusCode, String)>(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<BoxRoute> {
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]

View File

@ -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 = <Self::Body as axum::body::HttpBody>::Error;
fn into_response(self) -> Response<Body> {
fn into_response(self) -> Response<BoxBody> {
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(),
}
}