lib: destruct contants in http/unmarshaller.js (#152)
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
parent
8b67d36463
commit
b5a6673ace
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue