I'm using the reqwest integration for sending cloud events, but the content type seems to always be set to application/json instead of application/cloudevents+json.
Here's the request made to my pipedream request bin:
Cargo.toml
[package]
name = "cloudevents-reqwest-demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.75"
cloudevents-sdk = { version = "0.7.0", features = ["reqwest"] }
reqwest = "0.11.20"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
tokio = { version = "1.32.0", features = ["full"] }
uuid = { version = "1.4.1", features = ["v4"] }
main.rs
use std::collections::HashMap;
use cloudevents::binding::reqwest::RequestBuilderExt;
use cloudevents::{EventBuilder, EventBuilderV10};
#[tokio::main]
async fn main() {
let target = "https://<OMITTED>.m.pipedream.net";
let client = reqwest::Client::new();
let mut data = HashMap::new();
data.insert("hello", "world");
let event = EventBuilderV10::new()
.id(uuid::Uuid::new_v4().to_string())
.ty("example.test")
.source("http://localhost/")
.data("application/json", serde_json::to_value(data).unwrap())
.build()
.unwrap();
let resp = client
.post(target)
.event(event)
.unwrap()
.send()
.await
.unwrap();
println!("Response: {:?}", resp);
}
I've tried a few other things that don't seem to work:
Setting .data("application/cloudevents+json")
Setting a .header() for content type on the request builder
Using json!() serde macro for .data
I followed this example for getting set up, but I'm not using wasm.
That's not a bug. The sdk is using the Binary content mode to delivery the event using HTTP. In this mode, the HTTP Content-Type header corresponds to the CloudEvents datacontenttype attribute.
I'm using the
reqwest
integration for sending cloud events, but the content type seems to always be set toapplication/json
instead ofapplication/cloudevents+json
.Here's the request made to my pipedream request bin:
Cargo.toml
main.rs
I've tried a few other things that don't seem to work:
.data("application/cloudevents+json")
.header()
for content type on the request builderjson!()
serde macro for.data
I followed this example for getting set up, but I'm not using wasm.