New: check() decorator, parsersByEncoding to work with datacontentencoding
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
32a2590665
commit
fad43ecb4e
|
|
@ -23,15 +23,16 @@ function validateArgs(payload, attributes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function BinaryHTTPReceiver(
|
function BinaryHTTPReceiver(
|
||||||
parserByType,
|
parsersByEncoding,
|
||||||
setterByHeader,
|
setterByHeader,
|
||||||
allowedContentTypes,
|
allowedContentTypes,
|
||||||
requiredHeaders,
|
requiredHeaders,
|
||||||
Spec,
|
Spec,
|
||||||
specversion,
|
specversion,
|
||||||
extensionsPrefix) {
|
extensionsPrefix,
|
||||||
|
checkDecorator) {
|
||||||
|
|
||||||
this.parserByType = parserByType;
|
this.parsersByEncoding = parsersByEncoding;
|
||||||
this.setterByHeader = setterByHeader;
|
this.setterByHeader = setterByHeader;
|
||||||
this.allowedContentTypes = allowedContentTypes;
|
this.allowedContentTypes = allowedContentTypes;
|
||||||
this.requiredHeaders = requiredHeaders;
|
this.requiredHeaders = requiredHeaders;
|
||||||
|
|
@ -39,12 +40,17 @@ function BinaryHTTPReceiver(
|
||||||
this.spec = new Spec();
|
this.spec = new Spec();
|
||||||
this.specversion = specversion;
|
this.specversion = specversion;
|
||||||
this.extensionsPrefix = extensionsPrefix;
|
this.extensionsPrefix = extensionsPrefix;
|
||||||
|
this.checkDecorator = checkDecorator;
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryHTTPReceiver.prototype.check = function(payload, headers) {
|
BinaryHTTPReceiver.prototype.check = function(payload, headers) {
|
||||||
// Validation Level 0
|
// Validation Level 0
|
||||||
validateArgs(payload, headers);
|
validateArgs(payload, headers);
|
||||||
|
|
||||||
|
if(this.checkDecorator) {
|
||||||
|
this.checkDecorator(payload, headers);
|
||||||
|
}
|
||||||
|
|
||||||
// Clone and low case all headers names
|
// Clone and low case all headers names
|
||||||
var sanityHeaders = Commons.sanityAndClone(headers);
|
var sanityHeaders = Commons.sanityAndClone(headers);
|
||||||
|
|
||||||
|
|
@ -73,6 +79,11 @@ BinaryHTTPReceiver.prototype.check = function(payload, headers) {
|
||||||
// No erros! Its contains the minimum required attributes
|
// No erros! Its contains the minimum required attributes
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function parserFor(parsersByEncoding, cloudevent, headers){
|
||||||
|
let encoding = cloudevent.spec.payload["datacontentencoding"];
|
||||||
|
return parsersByEncoding[encoding][headers[Constants.HEADER_CONTENT_TYPE]];
|
||||||
|
}
|
||||||
|
|
||||||
BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
|
BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
|
||||||
this.check(payload, headers);
|
this.check(payload, headers);
|
||||||
|
|
||||||
|
|
@ -97,9 +108,9 @@ BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Parses the payload
|
// Parses the payload
|
||||||
var parsedPayload =
|
let parsedPayload =
|
||||||
this.parserByType[sanityHeaders[Constants.HEADER_CONTENT_TYPE]]
|
parserFor(this.parsersByEncoding, cloudevent, sanityHeaders)
|
||||||
.parse(payload);
|
.parse(payload);
|
||||||
|
|
||||||
// Every unprocessed header can be an extension
|
// Every unprocessed header can be an extension
|
||||||
Array.from(Object.keys(sanityHeaders))
|
Array.from(Object.keys(sanityHeaders))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue