diff --git a/lib/bindings/http/binary_0_1.js b/lib/bindings/http/binary_0_1.js index 076022a..4bca1a5 100644 --- a/lib/bindings/http/binary_0_1.js +++ b/lib/bindings/http/binary_0_1.js @@ -16,25 +16,40 @@ HTTPBinary.prototype.emit = function(cloudevent){ // Always set stuff in _config var _headers = _config["headers"]; + // OPTIONAL CONTENT TYPE ATTRIBUTE if(cloudevent.getContenttype()) { _headers["Content-Type"] = cloudevent.getContenttype(); } + // REQUIRED ATTRIBUTES _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(); + + // OPTIONAL ATTRIBUTES + 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/binary_0_2.js b/lib/bindings/http/binary_0_2.js index f4d6de1..916d538 100644 --- a/lib/bindings/http/binary_0_2.js +++ b/lib/bindings/http/binary_0_2.js @@ -17,21 +17,29 @@ HTTPBinary.prototype.emit = function(cloudevent){ // Always set stuff in _config var _headers = _config["headers"]; - _headers["Content-Type"] = cloudevent.getContenttype(); + // OPTIONAL CONTENT TYPE ATTRIBUTE + if (cloudevent.getContenttype()) { + _headers["Content-Type"] = cloudevent.getContenttype(); + } + // REQUIRED ATTRIBUTES _headers["ce-type"] = cloudevent.getType(); _headers["ce-specversion"] = cloudevent.getSpecversion(); _headers["ce-source"] = cloudevent.getSource(); _headers["ce-id"] = cloudevent.getId(); - if(cloudevent.getTime()) { + + // OPTIONAL ATTRIBUTES + if (cloudevent.getTime()) { _headers["ce-time"] = cloudevent.getTime(); } - _headers["ce-schemaurl"] = cloudevent.getSchemaurl(); + if (cloudevent.getSchemaurl()) { + _headers["ce-schemaurl"] = cloudevent.getSchemaurl(); + } // Set the cloudevent payload _config["data"] = cloudevent.format().data; - // Have extensions? + // EXTENSION CONTEXT ATTRIBUTES var exts = cloudevent.getExtensions(); for(var ext in exts){ if({}.hasOwnProperty.call(exts, ext)){