Skip to content

isCloudEvent Function #295

Closed
Closed

Description

@grant

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

Activity

  1. lance commented on Jul 31, 2020

    @lance
    Member

    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

  2. grant commented on Aug 11, 2020

    @grant
    MemberAuthor

    @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
  3. lance commented on Aug 11, 2020

    @lance
    Member

    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
  4. grant commented on Aug 11, 2020

    @grant
    MemberAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    module/libRelated to the main source codetype/enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions