Skip to content

Commit

Permalink
Upgrade dependencies, including http and hyper, where possible. (#233)
Browse files Browse the repository at this point in the history
* Upgrade axum.
Breaks docs.

Signed-off-by: Omar Zabala-Ferrera <[email protected]>

* Upgrade several dependencies.
delegate-attr, base64, snafu, bitflags, hostname, and serde_yaml.

Signed-off-by: Omar Zabala-Ferrera <[email protected]>

* Change target wasm32-wasi to wasm32-wasip1.

Signed-off-by: Omar Zabala-Ferrera <[email protected]>

---------

Signed-off-by: Omar Zabala-Ferrera <[email protected]>
  • Loading branch information
ozabalaferrera authored Dec 2, 2024
1 parent 9b38aea commit 09661dd
Show file tree
Hide file tree
Showing 47 changed files with 638 additions and 171 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- wasm32-unknown-unknown
- wasm32-wasi
- wasm32-wasip1
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -104,14 +104,14 @@ jobs:
with:
command: build
toolchain: ${{ matrix.toolchain }}
args: --target ${{ matrix.target }} --features "http-binding hyper hyper_wasi"
args: --target ${{ matrix.target }} --features "http-0-2-binding hyper-0-14 hyper_wasi"
- uses: actions-rs/cargo@v1
name: "Test"
if: matrix.target == 'wasm32-wasi'
with:
command: test
toolchain: ${{ matrix.toolchain }}
args: --target ${{ matrix.target }} --features "http-binding hyper hyper_wasi"
args: --target ${{ matrix.target }} --features "http-0-2-binding hyper-0-14 hyper_wasi"
env:
CARGO_TARGET_WASM32_WASI_RUNNER: wasmedge
# Build examples
Expand Down
51 changes: 27 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cloudevents-sdk"
version = "0.7.0"
version = "0.8.0"
authors = ["Francesco Guardiani <[email protected]>"]
license-file = "LICENSE"
edition = "2018"
Expand All @@ -23,72 +23,75 @@ name = "cloudevents"

[features]
http-binding = ["async-trait", "bytes", "futures", "http"]
actix = ["actix-web", "actix-http", "async-trait", "bytes", "futures", "http"]
http-0-2-binding = ["async-trait", "bytes", "futures", "http-0-2"]
actix = ["actix-web", "actix-http", "async-trait", "bytes", "futures", "http-0-2"]
reqwest = ["reqwest-lib", "async-trait", "bytes", "http", "uuid/js"]
rdkafka = ["rdkafka-lib", "bytes", "futures"]
warp = ["warp-lib", "bytes", "http", "hyper"]
axum = ["bytes", "http", "hyper", "axum-lib", "http-body", "async-trait"]
poem = ["bytes", "http", "poem-lib", "hyper", "async-trait"]
warp = ["warp-lib", "bytes", "http-0-2", "http-body-util", "hyper-0-14"]
axum = ["bytes", "http", "hyper", "axum-lib", "http-body-util", "async-trait"]
poem = ["bytes", "http", "poem-lib", "hyper", "async-trait", "http-body-util", "futures"]
nats = ["nats-lib"]

[dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
chrono = { version = "^0.4", features = ["serde"] }
delegate-attr = "^0.2"
base64 = "^0.12"
url = { version = "^2.1", features = ["serde"] }
snafu = "^0.6"
bitflags = "^1.2"
delegate-attr = "^0.3"
base64 = "^0.22"
url = { version = "^2.5", features = ["serde"] }
snafu = "^0.8"
bitflags = "^2.6"
uuid = { version = "1", features = ["v4"] }

# runtime optional deps
actix-web = { version = "4", optional = true }
actix-http = { version = "3", optional = true }
reqwest-lib = { version = "^0.11", default-features = false, features = ["rustls-tls"], optional = true, package = "reqwest" }
reqwest-lib = { version = "^0.12", default-features = false, features = ["rustls-tls"], optional = true, package = "reqwest" }
rdkafka-lib = { version = "^0.36", features = ["cmake-build"], optional = true, package = "rdkafka" }
warp-lib = { version = "^0.3", optional = true, package = "warp" }
async-trait = { version = "^0.1.33", optional = true }
async-trait = { version = "^0.1", optional = true }
bytes = { version = "^1.0", optional = true }
futures = { version = "^0.3", optional = true }
http = { version = "0.2", optional = true }
axum-lib = { version = "^0.6", optional = true, package="axum"}
http-body = { version = "^0.4", optional = true }
poem-lib = { version = "=1.2.34", optional = true, package = "poem" }
nats-lib = { version = "0.21.0", optional = true, package = "nats" }
futures = { version = "^0.3", optional = true, features = ["compat"]}
http = { version = "1.1", optional = true}
http-0-2 = { version = "0.2", optional = true, package = "http"}
axum-lib = { version = "^0.7", optional = true, package="axum"}
http-body-util = {version = "^0.1", optional = true}
poem-lib = { version = "^3.1", optional = true, package = "poem" }
nats-lib = { version = "0.25.0", optional = true, package = "nats" }

[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
hostname = "^0.3"
hostname = "^0.4"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
web-sys = { version = "^0.3", features = ["Window", "Location"] }

[target.'cfg(not(target_os = "wasi"))'.dependencies]
hyper = { version = "^0.14", optional = true }
hyper = { version = "^1.4", optional = true, package="hyper" }
hyper-0-14 = { version = "^0.14", optional = true, package = "hyper"}

[target.'cfg(all(target_arch = "wasm32", target_os = "wasi"))'.dependencies]
hyper_wasi = { version = "0.15", features = ["full"], optional = true }

[dev-dependencies]
rstest = "0.6"
rstest = "0.23"
claims = "0.7.1"
version-sync = "0.9.2"
serde_yaml = "0.8"
serde_yaml = "^0.9"
rmp-serde = "1"

# runtime dev-deps

url = { version = "^2.1", features = ["serde"] }
serde_json = { version = "^1.0" }
chrono = { version = "^0.4", features = ["serde"] }
mockito = "0.25.1"
mockito = "0.31.1"
mime = "0.3"


[target.'cfg(not(target_os = "wasi"))'.dev-dependencies]
actix-rt = { version = "^2" }
tokio = { version = "^1.0", features = ["full"] }
tower = { version = "0.4", features = ["util"] }
tower = { version = "0.5", features = ["util"] }

[target.'cfg(all(target_arch = "wasm32", target_os = "wasi"))'.dev-dependencies]
tokio_wasi = { version = "1", features = [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enabling your Protocol Binding of choice:

```toml
[dependencies]
cloudevents-sdk = { version = "0.7.0" }
cloudevents-sdk = { version = "0.8.0" }
```

Now you can start creating events:
Expand Down
4 changes: 2 additions & 2 deletions example-projects/actix-web-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
cloudevents-sdk = { path = "../..", features = ["actix"] }
actix-web = "4"
actix-cors = "0.6.0-beta.8"
actix-cors = "^0.7"
serde_json = "^1.0"
url = { version = "^2.1" }
env_logger = "0.7.1"
env_logger = "^0.11"
10 changes: 5 additions & 5 deletions example-projects/axum-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ edition = "2021"

[dependencies]
cloudevents-sdk = { path = "../..", features = ["axum"] }
axum = "^0.6"
http = "^0.2"
axum = "^0.7"
http = "^1.1"
tokio = { version = "^1", features = ["full"] }
tracing = "^0.1"
tracing-subscriber = "^0.2"
tower-http = { version = "^0.1", features = ["trace"] }
tracing-subscriber = "^0.3"
tower-http = { version = "^0.5", features = ["trace"] }

[dev-dependencies]
tower = { version = "^0.4", features = ["util"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
chrono = { version = "^0.4", features = ["serde"] }
hyper = { version = "^0.14" }
hyper = { version = "^1.4" }
9 changes: 2 additions & 7 deletions example-projects/axum-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use axum::{
};
use cloudevents::Event;
use http::StatusCode;
use std::net::SocketAddr;
use tower_http::trace::TraceLayer;

fn echo_app() -> Router {
Expand All @@ -27,12 +26,8 @@ async fn main() {
}
tracing_subscriber::fmt::init();
let service = echo_app();
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(service.into_make_service())
.await
.unwrap();
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
axum::serve(listener, service).await.unwrap();
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion example-projects/nats-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ edition = "2021"
[dependencies]
cloudevents-sdk = { path = "../..", features = ["nats"] }
serde_json = "^1.0"
nats = "0.21.0"
nats = "^0.25"
4 changes: 2 additions & 2 deletions example-projects/poem-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
cloudevents-sdk = { path = "../..", features = ["poem"] }
tokio = { version = "1.13", features = ["macros", "rt-multi-thread"] }
tracing = "0.1"
poem = { version = "1" }
tracing-subscriber = "0.2"
poem = { version = "^3.0" }
tracing-subscriber = "0.3"
serde_json = "1.0"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion example-projects/reqwest-wasm-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
crate-type = ["cdylib"]

[dependencies]
reqwest = "^0.11"
reqwest = "^0.12"
uuid = "1"
cloudevents-sdk = { path = "../..", features = ["reqwest"] }
url = { version = "^2.1" }
Expand Down
4 changes: 2 additions & 2 deletions example-projects/wasi-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
cloudevents-sdk = { path = "../..", features = ["http-binding", "hyper_wasi", "hyper" ] }
cloudevents-sdk = { path = "../..", features = ["http-0-2-binding", "hyper_wasi", "hyper-0-14" ] }
hyper_wasi = { version = "0.15", features = ["full"] }
log = "0.4.21"
tokio_wasi = { version = "1", features = ["io-util", "fs", "net", "time", "rt", "macros"] }
serde_json = " 1.0.116"
serde_json = "^1.0"

[dev-dependencies]
bytes = "1.6.0"
Expand Down
12 changes: 8 additions & 4 deletions example-projects/wasi-example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cloudevents::binding::http::builder::adapter::to_response;
use cloudevents::binding::http::to_event;
use cloudevents::binding::http_0_2::builder::adapter::to_response;
use cloudevents::binding::http_0_2::to_event;

use hyper::service::{make_service_fn, service_fn};
use hyper::Server;
Expand All @@ -23,7 +23,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
}
Ok(())
}
async fn handle_request(req: Request<Body>) -> Result<Response<Body>, anyhow::Error> {
async fn handle_request(
req: Request<Body>,
) -> Result<Response<Body>, anyhow::Error> {
match (req.method(), req.uri().path()) {
(&Method::POST, "/") => {
let headers = req.headers().clone();
Expand All @@ -34,7 +36,9 @@ async fn handle_request(req: Request<Body>) -> Result<Response<Body>, anyhow::Er

to_response(_respevt).map_err(|err| err.into())
}
(&Method::GET, "/health/readiness") => Ok(Response::new(Body::from(""))),
(&Method::GET, "/health/readiness") => {
Ok(Response::new(Body::from("")))
}
(&Method::GET, "/health/liveness") => Ok(Response::new(Body::from(""))),
_ => {
let mut not_found = Response::default();
Expand Down
3 changes: 2 additions & 1 deletion src/binding/actix/server_request.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::binding::http::{to_event, Headers};
use crate::binding::http_0_2::{to_event, Headers};
use crate::Event;
use actix_web::dev::Payload;
use actix_web::web::BytesMut;
use actix_web::{web, HttpRequest};
use async_trait::async_trait;
use futures::{future::LocalBoxFuture, FutureExt, StreamExt};
use http::header::{AsHeaderName, HeaderName, HeaderValue};
use http_0_2 as http;

/// Implement Headers for the actix HeaderMap
impl<'a> Headers<'a> for actix_http::header::HeaderMap {
Expand Down
3 changes: 2 additions & 1 deletion src/binding/actix/server_response.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::binding::http::{Builder, Serializer};
use crate::binding::http_0_2::{Builder, Serializer};
use crate::message::{BinaryDeserializer, Result};
use crate::Event;
use actix_web::http::StatusCode;
use actix_web::{HttpRequest, HttpResponse, HttpResponseBuilder};
use http_0_2 as http;

impl Builder<HttpResponse> for HttpResponseBuilder {
fn header(&mut self, key: &str, value: http::header::HeaderValue) {
Expand Down
53 changes: 27 additions & 26 deletions src/binding/axum/extract.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
use axum_lib as axum;

use async_trait::async_trait;
use axum::extract::FromRequest;
use axum::http::Request;
use http::request::Parts;
use axum::body::Bytes;
use axum::extract::{FromRequest, Request};
use axum::response::Response;
use axum_lib as axum;
use http;
use http::StatusCode;
use http_body::Body;
use hyper::body;

use crate::binding::http::to_event;
use crate::event::Event;

type BoxError = Box<dyn std::error::Error + Send + Sync>;

#[async_trait]
impl<S, B> FromRequest<S, B> for Event
impl<S> FromRequest<S> for Event
where
B: Body + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
Bytes: FromRequest<S>,
S: Send + Sync,
{
type Rejection = (StatusCode, String);

async fn from_request(req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
let (Parts { headers, .. }, req_body) = req.into_parts();
let buf = body::to_bytes(req_body)
.await
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e.into())))?
.to_vec();

to_event(&headers, buf).map_err(|e| (StatusCode::BAD_REQUEST, format!("{}", e)))
type Rejection = Response;

async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
let (parts, body) = req.into_parts();

let body = axum::body::to_bytes(body, usize::MAX).await.map_err(|e| {
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(axum::body::Body::from(e.to_string()))
.unwrap()
})?;

to_event(&parts.headers, body.to_vec()).map_err(|e| {
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(axum::body::Body::from(e.to_string()))
.unwrap()
})
}
}

#[cfg(test)]
mod tests {
use axum_lib as axum;

use super::*;
use axum::body::Body;
use axum::extract::FromRequest;
use axum::http::{self, Request, StatusCode};

use crate::test::fixtures;
Expand Down Expand Up @@ -80,7 +81,7 @@ mod tests {
assert!(result.is_err());
let rejection = result.unwrap_err();

let reason = rejection.0;
let reason = rejection.status();
assert_eq!(reason, StatusCode::BAD_REQUEST)
}

Expand Down
2 changes: 1 addition & 1 deletion src/binding/axum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ mod tests {
);

let (_, body) = resp.into_parts();
let body = hyper::body::to_bytes(body).await.unwrap();
let body = axum::body::to_bytes(body, usize::MAX).await.unwrap();

assert_eq!(j.to_string().as_bytes(), body);
}
Expand Down
Loading

0 comments on commit 09661dd

Please sign in to comment.