Skip to content

Commit d1f2720

Browse files
committed
closes #18
Signed-off-by: Fabio José <[email protected]>
1 parent bf4901f commit d1f2720

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

lib/bindings/http/emitter_binary_0_1.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ var axios = require("axios");
33
const Constants = require("./constants.js");
44

55
function HTTPBinary(configuration){
6-
this.config = configuration;
6+
this.config = JSON.parse(JSON.stringify(configuration));
77

88
if(!this.config["headers"]){
99
this.config["headers"] = {};
1010
}
1111

1212
this.config["headers"]
1313
[Constants.HEADER_CONTENT_TYPE] =
14-
Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT;
14+
Constants.MIME_JSON + "; charset=" + Constants.CHARSET_DEFAULT;
1515
}
1616

1717
HTTPBinary.prototype.emit = function(cloudevent){
@@ -22,25 +22,39 @@ HTTPBinary.prototype.emit = function(cloudevent){
2222
// Always set stuff in _config
2323
var _headers = _config["headers"];
2424

25+
// OPTIONAL CONTENT TYPE ATTRIBUTE
2526
if(cloudevent.getContenttype()) {
2627
_headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype();
2728
}
2829

2930
_headers["CE-EventType"] = cloudevent.getType();
30-
if(cloudevent.getEventTypeVersion()) {
31-
_headers["CE-EventTypeVersion"] = cloudevent.getEventTypeVersion();
32-
}
3331
_headers["CE-CloudEventsVersion"] = cloudevent.getSpecversion();
3432
_headers["CE-Source"] = cloudevent.getSource();
3533
_headers["CE-EventID"] = cloudevent.getId();
34+
35+
if(cloudevent.getEventTypeVersion()) {
36+
_headers["CE-EventTypeVersion"] = cloudevent.getEventTypeVersion();
37+
}
38+
3639
if(cloudevent.getTime()) {
3740
_headers["CE-EventTime"] = cloudevent.getTime();
3841
}
39-
_headers["CE-SchemaURL"] = cloudevent.getSchemaurl();
42+
if(cloudevent.getSchemaurl()) {
43+
_headers["CE-SchemaURL"] = cloudevent.getSchemaurl();
44+
}
4045

4146
// Set the cloudevent payload
4247
_config["data"] = cloudevent.format().data;
4348

49+
// EXTENSION CONTEXT ATTRIBUTES
50+
var exts = cloudevent.getExtensions();
51+
for(var ext in exts){
52+
if({}.hasOwnProperty.call(exts, ext)){
53+
let capsExt = ext.charAt(0).toUpperCase() + ext.slice(1)
54+
_headers["CE-X-" + capsExt] = exts[ext];
55+
}
56+
}
57+
4458
// Return the Promise
4559
return axios.request(_config);
4660
};

lib/bindings/http/emitter_binary_0_2.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ var empty = require("is-empty");
44
const Constants = require("./constants.js");
55

66
function HTTPBinary02(configuration){
7-
this.config = configuration;
7+
this.config = JSON.parse(JSON.stringify(configuration));
88

99
if(!this.config["headers"]){
1010
this.config["headers"] = {};
1111
}
1212

1313
this.config["headers"]
1414
[Constants.HEADER_CONTENT_TYPE] =
15-
Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT;
15+
Constants.MIME_JSON + "; charset=" + Constants.CHARSET_DEFAULT;
1616
}
1717

1818
HTTPBinary02.prototype.emit = function(cloudevent){
@@ -23,17 +23,24 @@ HTTPBinary02.prototype.emit = function(cloudevent){
2323
// Always set stuff in _config
2424
var _headers = _config["headers"];
2525

26-
_headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype();
26+
// OPTIONAL CONTENT TYPE ATTRIBUTE
27+
if (cloudevent.getContenttype()) {
28+
_headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype();
29+
}
2730

2831
_headers[Constants.BINARY_HEADERS_02.TYPE] = cloudevent.getType();
2932
_headers[Constants.BINARY_HEADERS_02.SPEC_VERSION] =
3033
cloudevent.getSpecversion();
3134
_headers[Constants.BINARY_HEADERS_02.SOURCE] = cloudevent.getSource();
3235
_headers[Constants.BINARY_HEADERS_02.ID] = cloudevent.getId();
36+
3337
if(cloudevent.getTime()) {
3438
_headers[Constants.BINARY_HEADERS_02.TIME] = cloudevent.getTime();
3539
}
36-
_headers[Constants.BINARY_HEADERS_02.SCHEMA_URL] = cloudevent.getSchemaurl();
40+
41+
if (cloudevent.getSchemaurl()) {
42+
_headers[Constants.BINARY_HEADERS_02.SCHEMA_URL] = cloudevent.getSchemaurl();
43+
}
3744

3845
// Set the cloudevent payload
3946
_config["data"] = cloudevent.format().data;

lib/bindings/http/emitter_structured_0_1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var axios = require("axios");
33
const Constants = require("./constants.js");
44

55
function HTTPStructured(configuration){
6-
this.config = configuration;
6+
this.config = JSON.parse(JSON.stringify(configuration));
77

88
if(!this.config["headers"]){
99
this.config["headers"] = {};

lib/bindings/http/emitter_structured_0_2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var axios = require("axios");
33
const Constants = require("./constants.js");
44

55
function HTTPStructured(configuration){
6-
this.config = configuration;
6+
this.config = JSON.parse(JSON.stringify(configuration));
77

88
if(!this.config["headers"]){
99
this.config["headers"] = {};

0 commit comments

Comments
 (0)