Skip to content

isCloudEvent Function #295

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

Closed
grant opened this issue Jul 31, 2020 · 4 comments · Fixed by #324
Closed

isCloudEvent Function #295

grant opened this issue Jul 31, 2020 · 4 comments · Fixed by #324
Labels
module/lib Related to the main source code type/enhancement New feature or request

Comments

@grant
Copy link
Member

grant commented Jul 31, 2020

Describe the Bug

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
@lance
Copy link
Member

lance commented 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
Copy link
Member Author

grant commented Aug 11, 2020

@lance What do you think about this logic?

https://github.com/cloudevents/sdk-javascript/blob/master/src/event/cloudevent.ts

  • static CloudEvent#isBinary
    • True if HTTP request has 4 required CE headers, otherwise false

@lance
Copy link
Member

lance commented Aug 11, 2020

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)
  • else return false

@grant
Copy link
Member Author

grant commented Aug 11, 2020

Yup, adding the method to the HTTP transport files instead of CloudEvent files makes sense.

@lance lance added module/lib Related to the main source code type/enhancement New feature or request labels Aug 17, 2020
lance added a commit that referenced this issue Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/lib Related to the main source code type/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants