Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-06-30 15:16:14 -03:00
parent bf4901f1e0
commit d1f27202e3
4 changed files with 33 additions and 12 deletions

View File

@ -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);
};

View File

@ -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;

View File

@ -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"] = {};

View File

@ -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"] = {};