Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

application/json content type set with reqwest integration insetad of expected application/cloudevents+json #214

Open
tizz98 opened this issue Sep 20, 2023 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@tizz98
Copy link

tizz98 commented Sep 20, 2023

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:

Screenshot

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:

  1. Setting .data("application/cloudevents+json")
  2. Setting a .header() for content type on the request builder
  3. Using json!() serde macro for .data

I followed this example for getting set up, but I'm not using wasm.

@Lazzaretti Lazzaretti added bug Something isn't working good first issue Good for newcomers labels May 22, 2024
@gabriel-araujjo
Copy link

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.

Source: https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md#311-http-content-type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants