From b5a6673ace35824c50f3675df216b6a7d8dd29c9 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 13 May 2020 17:22:05 +0200 Subject: [PATCH] lib: destruct contants in http/unmarshaller.js (#152) Signed-off-by: Daniel Bevenius --- lib/bindings/http/unmarshaller.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/bindings/http/unmarshaller.js b/lib/bindings/http/unmarshaller.js index d52164a..db79a8d 100644 --- a/lib/bindings/http/unmarshaller.js +++ b/lib/bindings/http/unmarshaller.js @@ -1,24 +1,30 @@ -const Constants = require("./constants.js"); +const { + HEADER_CONTENT_TYPE, + MIME_CE, + MIME_CE_JSON, + MIME_JSON, + MIME_OCTET_STREAM +} = require("./constants.js"); const Commons = require("./commons.js"); const STRUCTURED = "structured"; const BINARY = "binary"; const allowedBinaryContentTypes = [ - Constants.MIME_JSON, - Constants.MIME_OCTET_STREAM + MIME_JSON, + MIME_OCTET_STREAM ]; const allowedStructuredContentTypes = [ - Constants.MIME_CE_JSON + MIME_CE_JSON ]; // Is it binary or structured? function resolveBindingName(payload, headers) { const contentType = - Commons.sanityContentType(headers[Constants.HEADER_CONTENT_TYPE]); + Commons.sanityContentType(headers[HEADER_CONTENT_TYPE]); - if (contentType.startsWith(Constants.MIME_CE)) { + if (contentType.startsWith(MIME_CE)) { // Structured if (allowedStructuredContentTypes.includes(contentType)) { return STRUCTURED; @@ -54,7 +60,7 @@ class Unmarshaller { // Validation level 1 const sanityHeaders = Commons.sanityAndClone(headers); - if (!sanityHeaders[Constants.HEADER_CONTENT_TYPE]) { + if (!sanityHeaders[HEADER_CONTENT_TYPE]) { throw new TypeError("content-type header not found"); }