Merge pull request #15 from playground-julia/julia/adhereToSpec
Change binary http bindings to adhere to spec
This commit is contained in:
commit
ac6cf2793d
|
@ -1,10 +1,10 @@
|
||||||
var axios = require("axios");
|
var axios = require("axios");
|
||||||
|
|
||||||
function HTTPBinary(configuration){
|
function HTTPBinary(configuration){
|
||||||
this.config = configuration;
|
this.config = JSON.parse(JSON.stringify(configuration));
|
||||||
|
|
||||||
this.config["headers"] = {
|
this.config["headers"] = {
|
||||||
"Content-Type":"application/cloudevents+json; charset=utf-8"
|
"Content-Type":"application/json; charset=utf-8"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,25 +16,40 @@ HTTPBinary.prototype.emit = function(cloudevent){
|
||||||
// Always set stuff in _config
|
// Always set stuff in _config
|
||||||
var _headers = _config["headers"];
|
var _headers = _config["headers"];
|
||||||
|
|
||||||
|
// OPTIONAL CONTENT TYPE ATTRIBUTE
|
||||||
if(cloudevent.getContenttype()) {
|
if(cloudevent.getContenttype()) {
|
||||||
_headers["Content-Type"] = cloudevent.getContenttype();
|
_headers["Content-Type"] = cloudevent.getContenttype();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// REQUIRED ATTRIBUTES
|
||||||
_headers["CE-EventType"] = cloudevent.getType();
|
_headers["CE-EventType"] = cloudevent.getType();
|
||||||
if(cloudevent.getEventTypeVersion()) {
|
|
||||||
_headers["CE-EventTypeVersion"] = cloudevent.getEventTypeVersion();
|
|
||||||
}
|
|
||||||
_headers["CE-CloudEventsVersion"] = cloudevent.getSpecversion();
|
_headers["CE-CloudEventsVersion"] = cloudevent.getSpecversion();
|
||||||
_headers["CE-Source"] = cloudevent.getSource();
|
_headers["CE-Source"] = cloudevent.getSource();
|
||||||
_headers["CE-EventID"] = cloudevent.getId();
|
_headers["CE-EventID"] = cloudevent.getId();
|
||||||
|
|
||||||
|
// OPTIONAL ATTRIBUTES
|
||||||
|
if(cloudevent.getEventTypeVersion()) {
|
||||||
|
_headers["CE-EventTypeVersion"] = cloudevent.getEventTypeVersion();
|
||||||
|
}
|
||||||
if(cloudevent.getTime()) {
|
if(cloudevent.getTime()) {
|
||||||
_headers["CE-EventTime"] = cloudevent.getTime();
|
_headers["CE-EventTime"] = cloudevent.getTime();
|
||||||
}
|
}
|
||||||
|
if(cloudevent.getSchemaurl()) {
|
||||||
_headers["CE-SchemaURL"] = cloudevent.getSchemaurl();
|
_headers["CE-SchemaURL"] = cloudevent.getSchemaurl();
|
||||||
|
}
|
||||||
|
|
||||||
// Set the cloudevent payload
|
// Set the cloudevent payload
|
||||||
_config["data"] = cloudevent.format().data;
|
_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 the Promise
|
||||||
return axios.request(_config);
|
return axios.request(_config);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,10 +2,10 @@ var axios = require("axios");
|
||||||
var empty = require("is-empty");
|
var empty = require("is-empty");
|
||||||
|
|
||||||
function HTTPBinary(configuration){
|
function HTTPBinary(configuration){
|
||||||
this.config = configuration;
|
this.config = JSON.parse(JSON.stringify(configuration));
|
||||||
|
|
||||||
this.config["headers"] = {
|
this.config["headers"] = {
|
||||||
"Content-Type":"application/cloudevents+json; charset=utf-8"
|
"Content-Type":"application/json; charset=utf-8"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,21 +17,29 @@ HTTPBinary.prototype.emit = function(cloudevent){
|
||||||
// Always set stuff in _config
|
// Always set stuff in _config
|
||||||
var _headers = _config["headers"];
|
var _headers = _config["headers"];
|
||||||
|
|
||||||
|
// OPTIONAL CONTENT TYPE ATTRIBUTE
|
||||||
|
if (cloudevent.getContenttype()) {
|
||||||
_headers["Content-Type"] = cloudevent.getContenttype();
|
_headers["Content-Type"] = cloudevent.getContenttype();
|
||||||
|
}
|
||||||
|
|
||||||
|
// REQUIRED ATTRIBUTES
|
||||||
_headers["ce-type"] = cloudevent.getType();
|
_headers["ce-type"] = cloudevent.getType();
|
||||||
_headers["ce-specversion"] = cloudevent.getSpecversion();
|
_headers["ce-specversion"] = cloudevent.getSpecversion();
|
||||||
_headers["ce-source"] = cloudevent.getSource();
|
_headers["ce-source"] = cloudevent.getSource();
|
||||||
_headers["ce-id"] = cloudevent.getId();
|
_headers["ce-id"] = cloudevent.getId();
|
||||||
|
|
||||||
|
// OPTIONAL ATTRIBUTES
|
||||||
if (cloudevent.getTime()) {
|
if (cloudevent.getTime()) {
|
||||||
_headers["ce-time"] = cloudevent.getTime();
|
_headers["ce-time"] = cloudevent.getTime();
|
||||||
}
|
}
|
||||||
|
if (cloudevent.getSchemaurl()) {
|
||||||
_headers["ce-schemaurl"] = cloudevent.getSchemaurl();
|
_headers["ce-schemaurl"] = cloudevent.getSchemaurl();
|
||||||
|
}
|
||||||
|
|
||||||
// Set the cloudevent payload
|
// Set the cloudevent payload
|
||||||
_config["data"] = cloudevent.format().data;
|
_config["data"] = cloudevent.format().data;
|
||||||
|
|
||||||
// Have extensions?
|
// EXTENSION CONTEXT ATTRIBUTES
|
||||||
var exts = cloudevent.getExtensions();
|
var exts = cloudevent.getExtensions();
|
||||||
for(var ext in exts){
|
for(var ext in exts){
|
||||||
if({}.hasOwnProperty.call(exts, ext)){
|
if({}.hasOwnProperty.call(exts, ext)){
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
var axios = require("axios");
|
var axios = require("axios");
|
||||||
|
|
||||||
function HTTPStructured(configuration){
|
function HTTPStructured(configuration){
|
||||||
this.config = configuration;
|
this.config = JSON.parse(JSON.stringify(configuration));
|
||||||
|
|
||||||
this.config["headers"] = {
|
this.config["headers"] = {
|
||||||
"Content-Type":"application/cloudevents+json; charset=utf-8"
|
"Content-Type":"application/cloudevents+json; charset=utf-8"
|
||||||
|
@ -13,6 +13,7 @@ HTTPStructured.prototype.emit = function(cloudevent){
|
||||||
// Create new request object
|
// Create new request object
|
||||||
var _config = JSON.parse(JSON.stringify(this.config));
|
var _config = JSON.parse(JSON.stringify(this.config));
|
||||||
|
|
||||||
|
|
||||||
// Set the cloudevent payload
|
// Set the cloudevent payload
|
||||||
_config["data"] = cloudevent.format();
|
_config["data"] = cloudevent.format();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
var axios = require("axios");
|
var axios = require("axios");
|
||||||
|
|
||||||
function HTTPStructured(configuration){
|
function HTTPStructured(configuration){
|
||||||
this.config = configuration;
|
this.config = JSON.parse(JSON.stringify(configuration));
|
||||||
|
|
||||||
this.config["headers"] = {
|
this.config["headers"] = {
|
||||||
"Content-Type":"application/cloudevents+json; charset=utf-8"
|
"Content-Type":"application/cloudevents+json; charset=utf-8"
|
||||||
|
|
Loading…
Reference in New Issue