diff --git a/lib/bindings/http/emitter_binary_0_1.js b/lib/bindings/http/emitter_binary_0_1.js index 440b237..4918391 100644 --- a/lib/bindings/http/emitter_binary_0_1.js +++ b/lib/bindings/http/emitter_binary_0_1.js @@ -3,7 +3,7 @@ var axios = require("axios"); const Constants = require("./constants.js"); function HTTPBinary(configuration){ - this.config = configuration; + this.config = JSON.parse(JSON.stringify(configuration)); if(!this.config["headers"]){ this.config["headers"] = {}; @@ -11,7 +11,7 @@ function HTTPBinary(configuration){ this.config["headers"] [Constants.HEADER_CONTENT_TYPE] = - Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT; + Constants.MIME_JSON + "; charset=" + Constants.CHARSET_DEFAULT; } HTTPBinary.prototype.emit = function(cloudevent){ @@ -22,25 +22,39 @@ HTTPBinary.prototype.emit = function(cloudevent){ // Always set stuff in _config var _headers = _config["headers"]; + // OPTIONAL CONTENT TYPE ATTRIBUTE if(cloudevent.getContenttype()) { _headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype(); } _headers["CE-EventType"] = cloudevent.getType(); - if(cloudevent.getEventTypeVersion()) { - _headers["CE-EventTypeVersion"] = cloudevent.getEventTypeVersion(); - } _headers["CE-CloudEventsVersion"] = cloudevent.getSpecversion(); _headers["CE-Source"] = cloudevent.getSource(); _headers["CE-EventID"] = cloudevent.getId(); + + if(cloudevent.getEventTypeVersion()) { + _headers["CE-EventTypeVersion"] = cloudevent.getEventTypeVersion(); + } + if(cloudevent.getTime()) { _headers["CE-EventTime"] = cloudevent.getTime(); } - _headers["CE-SchemaURL"] = cloudevent.getSchemaurl(); + if(cloudevent.getSchemaurl()) { + _headers["CE-SchemaURL"] = cloudevent.getSchemaurl(); + } // Set the cloudevent payload _config["data"] = cloudevent.format().data; + // EXTENSION CONTEXT ATTRIBUTES + var exts = cloudevent.getExtensions(); + for(var ext in exts){ + if({}.hasOwnProperty.call(exts, ext)){ + let capsExt = ext.charAt(0).toUpperCase() + ext.slice(1) + _headers["CE-X-" + capsExt] = exts[ext]; + } + } + // Return the Promise return axios.request(_config); }; diff --git a/lib/bindings/http/emitter_binary_0_2.js b/lib/bindings/http/emitter_binary_0_2.js index 8e32940..f8bb057 100644 --- a/lib/bindings/http/emitter_binary_0_2.js +++ b/lib/bindings/http/emitter_binary_0_2.js @@ -4,7 +4,7 @@ var empty = require("is-empty"); const Constants = require("./constants.js"); function HTTPBinary02(configuration){ - this.config = configuration; + this.config = JSON.parse(JSON.stringify(configuration)); if(!this.config["headers"]){ this.config["headers"] = {}; @@ -12,7 +12,7 @@ function HTTPBinary02(configuration){ this.config["headers"] [Constants.HEADER_CONTENT_TYPE] = - Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT; + Constants.MIME_JSON + "; charset=" + Constants.CHARSET_DEFAULT; } HTTPBinary02.prototype.emit = function(cloudevent){ @@ -23,17 +23,24 @@ HTTPBinary02.prototype.emit = function(cloudevent){ // Always set stuff in _config var _headers = _config["headers"]; - _headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype(); + // OPTIONAL CONTENT TYPE ATTRIBUTE + if (cloudevent.getContenttype()) { + _headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype(); + } _headers[Constants.BINARY_HEADERS_02.TYPE] = cloudevent.getType(); _headers[Constants.BINARY_HEADERS_02.SPEC_VERSION] = cloudevent.getSpecversion(); _headers[Constants.BINARY_HEADERS_02.SOURCE] = cloudevent.getSource(); _headers[Constants.BINARY_HEADERS_02.ID] = cloudevent.getId(); + if(cloudevent.getTime()) { _headers[Constants.BINARY_HEADERS_02.TIME] = cloudevent.getTime(); } - _headers[Constants.BINARY_HEADERS_02.SCHEMA_URL] = cloudevent.getSchemaurl(); + + if (cloudevent.getSchemaurl()) { + _headers[Constants.BINARY_HEADERS_02.SCHEMA_URL] = cloudevent.getSchemaurl(); + } // Set the cloudevent payload _config["data"] = cloudevent.format().data; diff --git a/lib/bindings/http/emitter_structured_0_1.js b/lib/bindings/http/emitter_structured_0_1.js index 2031542..5448955 100644 --- a/lib/bindings/http/emitter_structured_0_1.js +++ b/lib/bindings/http/emitter_structured_0_1.js @@ -3,7 +3,7 @@ var axios = require("axios"); const Constants = require("./constants.js"); function HTTPStructured(configuration){ - this.config = configuration; + this.config = JSON.parse(JSON.stringify(configuration)); if(!this.config["headers"]){ this.config["headers"] = {}; diff --git a/lib/bindings/http/emitter_structured_0_2.js b/lib/bindings/http/emitter_structured_0_2.js index 2031542..5448955 100644 --- a/lib/bindings/http/emitter_structured_0_2.js +++ b/lib/bindings/http/emitter_structured_0_2.js @@ -3,7 +3,7 @@ var axios = require("axios"); const Constants = require("./constants.js"); function HTTPStructured(configuration){ - this.config = configuration; + this.config = JSON.parse(JSON.stringify(configuration)); if(!this.config["headers"]){ this.config["headers"] = {};