Http binary binding with constants
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
1e17cf165f
commit
043a4a8072
|
@ -3,7 +3,17 @@ var empty = require("is-empty");
|
|||
|
||||
const Constants = require("./constants.js");
|
||||
|
||||
function HTTPBinary(configuration){
|
||||
const Headers02 = {
|
||||
TYPE : "ce-type",
|
||||
SPEC_VERSION : "ce-specversion",
|
||||
SOURCE : "ce-source",
|
||||
ID : "ce-id",
|
||||
TIME : "ce-time",
|
||||
SCHEMA_URL : "ce-schemaurl",
|
||||
EXTENSIONS_PREFIX : "ce-"
|
||||
};
|
||||
|
||||
function HTTPBinary02(configuration){
|
||||
this.config = configuration;
|
||||
|
||||
if(!this.config["headers"]){
|
||||
|
@ -15,7 +25,7 @@ function HTTPBinary(configuration){
|
|||
Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT;
|
||||
}
|
||||
|
||||
HTTPBinary.prototype.emit = function(cloudevent){
|
||||
HTTPBinary02.prototype.emit = function(cloudevent){
|
||||
|
||||
// Create new request object
|
||||
var _config = JSON.parse(JSON.stringify(this.config));
|
||||
|
@ -25,14 +35,14 @@ HTTPBinary.prototype.emit = function(cloudevent){
|
|||
|
||||
_headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype();
|
||||
|
||||
_headers["ce-type"] = cloudevent.getType();
|
||||
_headers["ce-specversion"] = cloudevent.getSpecversion();
|
||||
_headers["ce-source"] = cloudevent.getSource();
|
||||
_headers["ce-id"] = cloudevent.getId();
|
||||
_headers[Headers02.TYPE] = cloudevent.getType();
|
||||
_headers[Headers02.SPEC_VERSION] = cloudevent.getSpecversion();
|
||||
_headers[Headers02.SOURCE] = cloudevent.getSource();
|
||||
_headers[Headers02.ID] = cloudevent.getId();
|
||||
if(cloudevent.getTime()) {
|
||||
_headers["ce-time"] = cloudevent.getTime();
|
||||
_headers[Headers02.TIME] = cloudevent.getTime();
|
||||
}
|
||||
_headers["ce-schemaurl"] = cloudevent.getSchemaurl();
|
||||
_headers[Headers02.SCHEMA_URL] = cloudevent.getSchemaurl();
|
||||
|
||||
// Set the cloudevent payload
|
||||
_config["data"] = cloudevent.format().data;
|
||||
|
@ -41,7 +51,7 @@ HTTPBinary.prototype.emit = function(cloudevent){
|
|||
var exts = cloudevent.getExtensions();
|
||||
for(var ext in exts){
|
||||
if({}.hasOwnProperty.call(exts, ext)){
|
||||
_headers["ce-" + ext] = exts[ext];
|
||||
_headers[Headers02.EXTENSIONS_PREFIX + ext] = exts[ext];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,4 +59,7 @@ HTTPBinary.prototype.emit = function(cloudevent){
|
|||
return axios.request(_config);
|
||||
};
|
||||
|
||||
module.exports = HTTPBinary;
|
||||
module.exports = {
|
||||
HTTPBinary02,
|
||||
Headers02
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ var JSONFormatter01 = require("./formats/json/formatter.js");
|
|||
var HTTPStructured01 = require("./bindings/http/emitter_structured_0_1.js");
|
||||
var HTTPStructured02 = require("./bindings/http/emitter_structured_0_2.js");
|
||||
var HTTPBinary01 = require("./bindings/http/emitter_binary_0_1.js");
|
||||
var HTTPBinary02 = require("./bindings/http/emitter_binary_0_2.js");
|
||||
var {HTTPBinary02} = require("./bindings/http/emitter_binary_0_2.js");
|
||||
|
||||
/*
|
||||
* Class created using the Builder Design Pattern.
|
||||
|
|
Loading…
Reference in New Issue