From d6032dda0d5431cb0f70be2b643f16d2a22fdc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Wed, 24 Jul 2019 15:33:08 -0300 Subject: [PATCH] Fix the content-type http header validation for binary format, in commons.js and unmarshaller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/bindings/http/commons.js | 19 ++++++++++++++++++- lib/bindings/http/unmarshaller_0_2.js | 5 +---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/bindings/http/commons.js b/lib/bindings/http/commons.js index 369faf5..cd6dc14 100644 --- a/lib/bindings/http/commons.js +++ b/lib/bindings/http/commons.js @@ -1,3 +1,16 @@ +const Constants = require("./constants.js"); + +function sanityContentType(contentType) { + if(contentType) { + return Array.of(contentType) + .map(c => c.split(";")) + .map(c => c.shift()) + .shift(); + } + + return contentType; +} + function sanityAndClone(headers) { var sanityHeaders = {}; @@ -8,9 +21,13 @@ function sanityAndClone(headers) { sanityHeaders[header.toLowerCase()] = headers[header]; }); + sanityHeaders[Constants.HEADER_CONTENT_TYPE] = + sanityContentType(sanityHeaders[Constants.HEADER_CONTENT_TYPE]); + return sanityHeaders; } module.exports = { - sanityAndClone + sanityAndClone, + sanityContentType }; diff --git a/lib/bindings/http/unmarshaller_0_2.js b/lib/bindings/http/unmarshaller_0_2.js index 4454bda..8ecce98 100644 --- a/lib/bindings/http/unmarshaller_0_2.js +++ b/lib/bindings/http/unmarshaller_0_2.js @@ -32,10 +32,7 @@ function validateArgs(payload, headers) { function resolveBindingName(payload, headers) { var contentType = - Array.of(headers[Constants.HEADER_CONTENT_TYPE]) - .map(c => c.split(";")) - .map(c => c.shift()) - .shift(); + Commons.sanityContentType(headers[Constants.HEADER_CONTENT_TYPE]); if(contentType.startsWith(Constants.MIME_CE)){ // Structured