Skip to content

Commit d1fc0b3

Browse files
committed
Parse content type, sanity in parse method
Signed-off-by: Fabio José <fabiojose@gmail.com>
1 parent 21011b5 commit d1fc0b3

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/bindings/http/receiver_binary_0_2.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ setter_reflections[Constants.BINARY_HEADERS_02.SCHEMA_URL] = {
3232
name: "schemaurl",
3333
parser: (v) => v
3434
};
35+
setter_reflections[Constants.HEADER_CONTENT_TYPE] = {
36+
name: "contenttype",
37+
parser: (v) => v
38+
};
3539

3640
function validate_args(payload, attributes) {
3741
if(!payload){
@@ -93,15 +97,18 @@ Receiver.prototype.check = function(payload, headers) {
9397
Receiver.prototype.parse = function(payload, headers) {
9498
this.check(payload, headers);
9599

100+
// Clone and low case all headers names
101+
var sanity_headers = sanity(headers);
102+
96103
var cloudevent = new Cloudevent(Spec02);
97104
for(header in setter_reflections) {
98105
// dont worry, check() have seen what was required or not
99-
if(headers[header]){
106+
if(sanity_headers[header]){
100107
var setter_name = setter_reflections[header].name;
101108
var parser_fn = setter_reflections[header].parser;
102109

103110
// invoke the setter function
104-
cloudevent[setter_name](parser_fn(headers[header]));
111+
cloudevent[setter_name](parser_fn(sanity_headers[header]));
105112
}
106113
}
107114

test/bindings/http/receiver_binary_0_2_tests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,29 @@ describe("HTTP Transport Binding Binary Receiver 0.2", () => {
285285
.to.equal("http://schema.registry/v1");
286286
});
287287

288+
it("Cloudevent contains 'contenttype'", () => {
289+
// setup
290+
var payload = {
291+
"data" : "dataString"
292+
};
293+
var attributes = {
294+
"ce-type" : "type",
295+
"ce-specversion" : "0.2",
296+
"ce-source" : "/source",
297+
"ce-id" : "id",
298+
"ce-time" : "2019-06-16T11:42:00Z",
299+
"ce-schemaurl" : "http://schema.registry/v1",
300+
"Content-Type" : "application/json"
301+
};
302+
303+
// act
304+
var actual = receiver.parse(payload, attributes);
305+
306+
// assert
307+
expect(actual.getContenttype())
308+
.to.equal("application/json");
309+
});
310+
288311
it("Cloudevent contains 'data'", () => {
289312
// setup
290313
var payload = {

0 commit comments

Comments
 (0)