Skip to content

emitter.send() drops datacontenttype header #240

New issue

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

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

Already on GitHub? # to your account

Closed
c-pius opened this issue Jul 6, 2020 · 5 comments
Closed

emitter.send() drops datacontenttype header #240

c-pius opened this issue Jul 6, 2020 · 5 comments
Labels
version/2.x Issues related to the 2.x version of this module

Comments

@c-pius
Copy link

c-pius commented Jul 6, 2020

Not entirely sure on this but I think emitter.send() drops the datacontenttype header.

structured

const event = new CloudEvent({
    id: "4711",
    type: "foo",
    source: "bar",
    datacontenttype: "text/xml",
    data: "<xml>test</xml>"
});

emitter.send(event, { mode: "structured" }).then((response) => {
    console.log(`status: ${response.status} ${response.statusText}`)
}).catch(console.error)

received content-type header : "application/cloudevents+json"

received payload:

{
    "data": "<xml>test</xml>",
    "specversion": "1.0",
    "id": "4711",
    "time": "2020-07-06T06:56:01.645Z",
    "source": "bar",
    "type": "foo"
}

binary

const event = new CloudEvent({
    id: "4711",
    type: "foo",
    source: "bar",
    datacontenttype: "text/xml",
    data: "<xml>test</xml>"
});

emitter.send(event, { mode: "binary" }).then((response) => {
    console.log(`status: ${response.status} ${response.statusText}`)
}).catch(console.error)

received content-type header = "application/json"

I assume the datacontenttype is dropped (not allowed in binary binding). But then the missing value is defaulted to application/json for the content-type header (seems correct from the spec). However, the content-type header should be set to "text/xml" from the given datacontenttype value.

@lance lance added type/bug Something isn't working version/3.x Issues related to the 3.0 release of this library labels Jul 6, 2020
@lance lance changed the title emitter.send() drops datacontenttype header? emitter.send() drops datacontenttype header Jul 6, 2020
@lance
Copy link
Member

lance commented Jul 6, 2020

For binary mode, the ce-datacontenttype header MUST NOT be present in the message. But you are correct that the content-type header should be text/xml in this case.

For structured mode, the received payload should have the datacontenttype property.

Thanks for reporting this.

@lance lance added version/2.x Issues related to the 2.x version of this module and removed version/3.x Issues related to the 3.0 release of this library labels Jul 6, 2020
@lance
Copy link
Member

lance commented Jul 6, 2020

I have been testing the binary mode transmission, and realized that you need to use dataContentType. If you do, your scenario should work. Still poking structured mode.

@lance
Copy link
Member

lance commented Jul 6, 2020

@c-pius the module is working as expected for both binary and structured events. In both cases, the property on the CloudEvent object is dataContentType. I'm going to close this as not-a-bug. If you find additional problems please feel free to reopen or create a new issue.

@lance lance closed this as completed Jul 6, 2020
@lance lance removed the type/bug Something isn't working label Jul 6, 2020
@c-pius
Copy link
Author

c-pius commented Jul 7, 2020

ah okay, sorry for the confusion. Will this change with the new release however? I was looking at the examples and that is actually where I got the all lowercase datacontenttype from

datacontenttype: "text/plain",

@lance
Copy link
Member

lance commented Jul 7, 2020

@c-pius yes - the examples are previewing what will be coming in 3.0.0. You can track the release of that in this issue. We made this change to simplify marshaling/unmarshaling of CloudEvent objects, since the specification requires event attributes to be in all lowercase.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
version/2.x Issues related to the 2.x version of this module
Projects
None yet
Development

No branches or pull requests

2 participants