Code style: camelCase
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
5ec82401ec
commit
162e78f507
|
@ -7,18 +7,18 @@ const Commons = require("./commons.js");
|
|||
const structured = "structured";
|
||||
const binary = "binary";
|
||||
|
||||
const receiver_by_binding = {
|
||||
const receiverByBinding = {
|
||||
structured : new StructuredReceiver(),
|
||||
binary : new BinaryReceiver(),
|
||||
};
|
||||
|
||||
const allowed_binary_content_types = [];
|
||||
allowed_binary_content_types.push(Constants.MIME_JSON);
|
||||
const allowedBinaryContentTypes = [];
|
||||
allowedBinaryContentTypes.push(Constants.MIME_JSON);
|
||||
|
||||
const allowed_structured_content_types = [];
|
||||
allowed_structured_content_types.push(Constants.MIME_CE_JSON);
|
||||
const allowedStructuredContentTypes = [];
|
||||
allowedStructuredContentTypes.push(Constants.MIME_CE_JSON);
|
||||
|
||||
function validate_args(payload, headers) {
|
||||
function validateArgs(payload, headers) {
|
||||
if(!payload){
|
||||
throw {message: "payload is null or undefined"};
|
||||
}
|
||||
|
@ -29,19 +29,19 @@ function validate_args(payload, headers) {
|
|||
}
|
||||
|
||||
// Is it binary or structured?
|
||||
function resolve_binding_name(payload, headers) {
|
||||
function resolveBindingName(payload, headers) {
|
||||
|
||||
var contentType = headers[Constants.HEADER_CONTENT_TYPE];
|
||||
if(contentType.startsWith(Constants.MIME_CE)){
|
||||
// Structured
|
||||
if(allowed_structured_content_types.includes(contentType)){
|
||||
if(allowedStructuredContentTypes.includes(contentType)){
|
||||
return structured;
|
||||
} else {
|
||||
throw {message: "structured+type not allowed", errors: [contentType]};
|
||||
}
|
||||
} else {
|
||||
// Binary
|
||||
if(allowed_binary_content_types.includes(contentType)){
|
||||
if(allowedBinaryContentTypes.includes(contentType)){
|
||||
return binary;
|
||||
} else {
|
||||
throw {message: "content type not allowed", errors : [contentType]};
|
||||
|
@ -56,20 +56,20 @@ var Unmarshaller = function() {
|
|||
Unmarshaller.prototype.unmarshall = function(payload, headers) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
validate_args(payload, headers);
|
||||
validateArgs(payload, headers);
|
||||
|
||||
var sanity_headers = Commons.sanity_and_clone(headers);
|
||||
var sanityHeaders = Commons.sanity_and_clone(headers);
|
||||
|
||||
// Validation level 1
|
||||
if(!sanity_headers[Constants.HEADER_CONTENT_TYPE]){
|
||||
if(!sanityHeaders[Constants.HEADER_CONTENT_TYPE]){
|
||||
throw {message: "content-type header not found"};
|
||||
}
|
||||
|
||||
// Resolve the binding
|
||||
var binding_name = resolve_binding_name(payload, sanity_headers);
|
||||
var bindingName = resolveBindingName(payload, sanityHeaders);
|
||||
|
||||
var cloudevent =
|
||||
receiver_by_binding[binding_name].parse(payload, sanity_headers);
|
||||
receiverByBinding[bindingName].parse(payload, sanityHeaders);
|
||||
|
||||
resolve(cloudevent);
|
||||
}catch(e){
|
||||
|
|
Loading…
Reference in New Issue