lib: destruct contants in http/unmarshaller.js (#152)

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
Daniel Bevenius 2020-05-13 17:22:05 +02:00 committed by GitHub
parent 8b67d36463
commit b5a6673ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -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");
}