From 1024a70d419be633d23fe2f3ddc5a1451700b11b Mon Sep 17 00:00:00 2001 From: Julia Huang Date: Tue, 11 Jun 2019 14:37:03 -0700 Subject: [PATCH 1/3] Fix Content Type of binary format Signed-off-by: Julia Huang --- lib/bindings/http/binary_0_1.js | 2 +- lib/bindings/http/binary_0_2.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bindings/http/binary_0_1.js b/lib/bindings/http/binary_0_1.js index 5bac97b..076022a 100644 --- a/lib/bindings/http/binary_0_1.js +++ b/lib/bindings/http/binary_0_1.js @@ -4,7 +4,7 @@ function HTTPBinary(configuration){ this.config = configuration; this.config["headers"] = { - "Content-Type":"application/cloudevents+json; charset=utf-8" + "Content-Type":"application/json; charset=utf-8" }; } diff --git a/lib/bindings/http/binary_0_2.js b/lib/bindings/http/binary_0_2.js index 8d249e5..f4d6de1 100644 --- a/lib/bindings/http/binary_0_2.js +++ b/lib/bindings/http/binary_0_2.js @@ -5,7 +5,7 @@ function HTTPBinary(configuration){ this.config = configuration; this.config["headers"] = { - "Content-Type":"application/cloudevents+json; charset=utf-8" + "Content-Type":"application/json; charset=utf-8" }; } From 0d56db725be2d1f1572937eff1ee99f7bccee0fe Mon Sep 17 00:00:00 2001 From: Julia Huang Date: Tue, 11 Jun 2019 14:38:07 -0700 Subject: [PATCH 2/3] Make optional specs optional and reorganize files Signed-off-by: Julia Huang --- lib/bindings/http/binary_0_1.js | 23 +++++++++++++++++++---- lib/bindings/http/binary_0_2.js | 16 ++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) 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)){ From b60454234b1c29df553cf82192ede76b233aa295 Mon Sep 17 00:00:00 2001 From: Julia Huang Date: Tue, 11 Jun 2019 14:22:47 -0700 Subject: [PATCH 3/3] Make a copy of configuration being passed in - tests should now be passing Signed-off-by: Julia Huang --- lib/bindings/http/binary_0_1.js | 2 +- lib/bindings/http/binary_0_2.js | 2 +- lib/bindings/http/structured_0_1.js | 3 ++- lib/bindings/http/structured_0_2.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/bindings/http/binary_0_1.js b/lib/bindings/http/binary_0_1.js index 4bca1a5..240401c 100644 --- a/lib/bindings/http/binary_0_1.js +++ b/lib/bindings/http/binary_0_1.js @@ -1,7 +1,7 @@ var axios = require("axios"); function HTTPBinary(configuration){ - this.config = configuration; + this.config = JSON.parse(JSON.stringify(configuration)); this.config["headers"] = { "Content-Type":"application/json; charset=utf-8" diff --git a/lib/bindings/http/binary_0_2.js b/lib/bindings/http/binary_0_2.js index 916d538..822bf41 100644 --- a/lib/bindings/http/binary_0_2.js +++ b/lib/bindings/http/binary_0_2.js @@ -2,7 +2,7 @@ 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/json; charset=utf-8" diff --git a/lib/bindings/http/structured_0_1.js b/lib/bindings/http/structured_0_1.js index 65c6530..cf35282 100644 --- a/lib/bindings/http/structured_0_1.js +++ b/lib/bindings/http/structured_0_1.js @@ -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" @@ -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(); diff --git a/lib/bindings/http/structured_0_2.js b/lib/bindings/http/structured_0_2.js index 65c6530..fd45956 100644 --- a/lib/bindings/http/structured_0_2.js +++ b/lib/bindings/http/structured_0_2.js @@ -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"