You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there an easy way to determine if a HTTP request is a CloudEvent or not?
It would be great if there was a isCloudEvent function or something similar. Maybe just documentation if we can re-use existing functions together to achieve this.
Steps to Reproduce
Try to find a function to determine if a HTTP request is a valid CE
Expected Behavior
Documentation in the main README for how to determine if a HTTP req is a CE
We do not have that in this module, although I can see it being useful. For a current project I am working on, we do this before trying to parse the event.
Hmm - I don't think that it makes sense for a static isBinary method on CloudEvent because a CloudEvent itself is neither binary or structured. Those are just transport representations and really only make sense in the context of an incoming request over a transport protocol.
This would make more sense as a standalone function in cloudevents/transport/http. The logic for an isCloudEvent (distinct from isBinary) method should be something like this:
if the content-type header is set to an event format media type return true (it's a structured event)
if the ce-id, ce-type, ce-source and ce-specversion headers exist return true (it's a binary event)
Activity
lance commentedon Jul 31, 2020
We do not have that in this module, although I can see it being useful. For a current project I am working on, we do this before trying to parse the event.
https://github.com/boson-project/faas-js-runtime/blob/master/lib/event-handler.js#L32-L48
grant commentedon Aug 11, 2020
@lance What do you think about this logic?
https://github.com/cloudevents/sdk-javascript/blob/master/src/event/cloudevent.ts
staticCloudEvent#isBinarylance commentedon Aug 11, 2020
Hmm - I don't think that it makes sense for a static
isBinarymethod onCloudEventbecause aCloudEventitself is neither binary or structured. Those are just transport representations and really only make sense in the context of an incoming request over a transport protocol.This would make more sense as a standalone function in
cloudevents/transport/http. The logic for anisCloudEvent(distinct fromisBinary) method should be something like this:content-typeheader is set to an event format media type return true (it's a structured event)ce-id,ce-type,ce-sourceandce-specversionheaders exist return true (it's a binary event)grant commentedon Aug 11, 2020
Yup, adding the method to the HTTP transport files instead of CloudEvent files makes sense.
src(message): adds Detector interface to ease detection of events