From fea87aaee2c2169195110da706ad043876a6b536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Fri, 21 Jun 2019 10:58:05 -0300 Subject: [PATCH] Using the Spec to check the format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/bindings/http/receiver_structured_0_2.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/bindings/http/receiver_structured_0_2.js b/lib/bindings/http/receiver_structured_0_2.js index e5cacd3..dd7e044 100644 --- a/lib/bindings/http/receiver_structured_0_2.js +++ b/lib/bindings/http/receiver_structured_0_2.js @@ -5,7 +5,8 @@ const Spec02 = require("../../specs/spec_0_2.js"); var JSONParser = require("../../formats/json/parser.js"); -const jsonParserSpec02 = new JSONParser(new Spec02()); +const spec02 = new Spec02(); +const jsonParserSpec02 = new JSONParser(); const parser_by_mime = {}; parser_by_mime[Constants.MIME_JSON] = jsonParserSpec02; @@ -56,9 +57,12 @@ Receiver.prototype.parse = function(payload, headers) { var contentType = sanity_headers[Constants.HEADER_CONTENT_TYPE]; var parser = parser_by_mime[contentType]; - + var cloudevent = parser.parse(payload); + // Must follow the spec + spec02.check(cloudevent); + return cloudevent; }