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(
|
||||
parserByType,
|
||||
parsersByEncoding,
|
||||
setterByHeader,
|
||||
allowedContentTypes,
|
||||
requiredHeaders,
|
||||
Spec,
|
||||
specversion,
|
||||
extensionsPrefix) {
|
||||
extensionsPrefix,
|
||||
checkDecorator) {
|
||||
|
||||
this.parserByType = parserByType;
|
||||
this.parsersByEncoding = parsersByEncoding;
|
||||
this.setterByHeader = setterByHeader;
|
||||
this.allowedContentTypes = allowedContentTypes;
|
||||
this.requiredHeaders = requiredHeaders;
|
||||
|
|
@ -39,12 +40,17 @@ function BinaryHTTPReceiver(
|
|||
this.spec = new Spec();
|
||||
this.specversion = specversion;
|
||||
this.extensionsPrefix = extensionsPrefix;
|
||||
this.checkDecorator = checkDecorator;
|
||||
}
|
||||
|
||||
BinaryHTTPReceiver.prototype.check = function(payload, headers) {
|
||||
// Validation Level 0
|
||||
validateArgs(payload, headers);
|
||||
|
||||
if(this.checkDecorator) {
|
||||
this.checkDecorator(payload, headers);
|
||||
}
|
||||
|
||||
// Clone and low case all headers names
|
||||
var sanityHeaders = Commons.sanityAndClone(headers);
|
||||
|
||||
|
|
@ -73,6 +79,11 @@ BinaryHTTPReceiver.prototype.check = function(payload, headers) {
|
|||
// 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) {
|
||||
this.check(payload, headers);
|
||||
|
||||
|
|
@ -97,9 +108,9 @@ BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
|
|||
});
|
||||
|
||||
// Parses the payload
|
||||
var parsedPayload =
|
||||
this.parserByType[sanityHeaders[Constants.HEADER_CONTENT_TYPE]]
|
||||
.parse(payload);
|
||||
let parsedPayload =
|
||||
parserFor(this.parsersByEncoding, cloudevent, sanityHeaders)
|
||||
.parse(payload);
|
||||
|
||||
// Every unprocessed header can be an extension
|
||||
Array.from(Object.keys(sanityHeaders))
|
||||
|
|
|
|||
Loading…
Reference in New Issue