Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/bindings/http/unmarshaller.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down