Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions lib/bindings/http/binary_0_1.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var axios = require("axios");

function HTTPBinary(configuration){
this.config = configuration;
this.config = JSON.parse(JSON.stringify(configuration));

this.config["headers"] = {
"Content-Type":"application/cloudevents+json; charset=utf-8"
"Content-Type":"application/json; charset=utf-8"
};
}

Expand All @@ -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);
};
Expand Down
20 changes: 14 additions & 6 deletions lib/bindings/http/binary_0_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var axios = require("axios");
var empty = require("is-empty");

function HTTPBinary(configuration){
this.config = configuration;
this.config = JSON.parse(JSON.stringify(configuration));

this.config["headers"] = {
"Content-Type":"application/cloudevents+json; charset=utf-8"
"Content-Type":"application/json; charset=utf-8"
};
}

Expand All @@ -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)){
Expand Down
3 changes: 2 additions & 1 deletion lib/bindings/http/structured_0_1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var axios = require("axios");

function HTTPStructured(configuration){
this.config = configuration;
this.config = JSON.parse(JSON.stringify(configuration));

this.config["headers"] = {
"Content-Type":"application/cloudevents+json; charset=utf-8"
Expand All @@ -13,6 +13,7 @@ HTTPStructured.prototype.emit = function(cloudevent){
// Create new request object
var _config = JSON.parse(JSON.stringify(this.config));


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

Expand Down
2 changes: 1 addition & 1 deletion lib/bindings/http/structured_0_2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var axios = require("axios");

function HTTPStructured(configuration){
this.config = configuration;
this.config = JSON.parse(JSON.stringify(configuration));

this.config["headers"] = {
"Content-Type":"application/cloudevents+json; charset=utf-8"
Expand Down