When serializing string valued CloudEvent attributes in HTTP Binary Content Mode, is the value surrounded by double quotes?
I.e., I want to serialize a cloud event of type com.example.someevent in HTTP Binary Content mode. What does its HTTP headers look like?
Spec
The existing spec states: "The value for each HTTP header is constructed from the respective attribute's JSON value representation, compliant with the JSON event format specification."
This means that every string value MUST to be surrounded by double quotes. And implies that when a compliant program parses the HTTP request, they MUST JSON unmarshal the header's value to obtain the Cloud Event's value.
This is supported by the examples in the spec:
POST /someresource HTTP/1.1
Host: webhook.example.com
ce-specversion: "0.2"
ce-type: "com.example.someevent"
ce-time: "2018-04-05T03:56:24Z"
ce-id: "1234-1234-1234"
ce-source: "/mycontext/subcontext"
.... further attributes ...
Content-Type: application/json; charset=utf-8
Content-Length: nnnn
{
... application data ...
}
Note that the ce-type header's value is "com.example.someevent", not com.example.someevent. This is the example from the Structured Content Mode:
PUT /myresource HTTP/1.1
Host: webhook.example.com
Content-Type: application/cloudevents+json; charset=utf-8
Content-Length: nnnn
{
"specversion" : "0.2",
"type" : "com.example.someevent",
... further attributes omitted ...
"data" : {
... application data ...
}
}
This example unambiguously states the type as com.example.someevent (note that lack of quotes). Assuming that the two examples are supposed to show the same Cloud Event serialized in two different ways (albeit omitting some fields), then it seems that in Binary Content Mode, the value MUST be surrounded by double quotes.
Implementations
However, every implementation I have come across not only doesn't emit the quotes, it also doesn't handle them when parsing a request. They all treat the double quotes as part of the value. E.g. the type is "com.example.someevent".
Possible Solutions
- Redefine the spec to not have double quotes around string values.
- Note that this makes it difficult/impossible to distinguish between strings that happen to look like valid JSON, and that JSON itself. E.g. if the HTTP header is
ce-foo: {}, is the value the string {} or the empty JSON object?
- Would this be only on 0.3 and newer? Or retroactively changed for 0.1 and 0.2? If not retroactive, then we likely need the next solution in addition to this one.
- Change the implementations to follow the spec.
When serializing string valued CloudEvent attributes in HTTP Binary Content Mode, is the value surrounded by double quotes?
I.e., I want to serialize a cloud event of type
com.example.someeventin HTTP Binary Content mode. What does its HTTP headers look like?Spec
The existing spec states: "The value for each HTTP header is constructed from the respective attribute's JSON value representation, compliant with the JSON event format specification."
This means that every string value MUST to be surrounded by double quotes. And implies that when a compliant program parses the HTTP request, they MUST JSON unmarshal the header's value to obtain the Cloud Event's value.
This is supported by the examples in the spec:
Note that the
ce-typeheader's value is"com.example.someevent", notcom.example.someevent. This is the example from the Structured Content Mode:This example unambiguously states the type as
com.example.someevent(note that lack of quotes). Assuming that the two examples are supposed to show the same Cloud Event serialized in two different ways (albeit omitting some fields), then it seems that in Binary Content Mode, the value MUST be surrounded by double quotes.Implementations
However, every implementation I have come across not only doesn't emit the quotes, it also doesn't handle them when parsing a request. They all treat the double quotes as part of the value. E.g. the type is
"com.example.someevent".Possible Solutions
ce-foo: {}, is the value the string{}or the empty JSON object?