Headers as constants
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
441613b103
commit
cc41f0e015
|
@ -13,11 +13,11 @@ const Headers02 = {
|
||||||
EXTENSIONS_PREFIX : "ce-"
|
EXTENSIONS_PREFIX : "ce-"
|
||||||
};
|
};
|
||||||
|
|
||||||
const required_attributes = [];
|
const required_headers = [];
|
||||||
required_attributes.push(Headers02.TYPE);
|
required_headers.push(Headers02.TYPE);
|
||||||
required_attributes.push(Headers02.SPEC_VERSION);
|
required_headers.push(Headers02.SPEC_VERSION);
|
||||||
required_attributes.push(Headers02.SOURCE);
|
required_headers.push(Headers02.SOURCE);
|
||||||
required_attributes.push(Headers02.ID);
|
required_headers.push(Headers02.ID);
|
||||||
|
|
||||||
function validate_args(payload, attributes) {
|
function validate_args(payload, attributes) {
|
||||||
if(!payload){
|
if(!payload){
|
||||||
|
@ -45,18 +45,24 @@ function HTTPBinary02(configuration){
|
||||||
Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT;
|
Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPBinary02.prototype.check = function(payload, attributes) {
|
HTTPBinary02.prototype.check = function(payload, headers) {
|
||||||
// Validation Level 0
|
// Validation Level 0
|
||||||
validate_args(payload, attributes);
|
validate_args(payload, headers);
|
||||||
|
|
||||||
// Validation Level 1
|
// Validation Level 1
|
||||||
for(i in required_attributes){
|
for(i in required_headers){
|
||||||
if(!attributes[required_attributes[i]]){
|
if(!headers[required_headers[i]]){
|
||||||
throw {message: "header '" + required_attributes[i] + "' not found"};
|
throw {message: "header '" + required_headers[i] + "' not found"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No erros! Its contains the minimum required attributes
|
||||||
|
}
|
||||||
|
|
||||||
|
HTTPBinary02.prototype.parse = function(payload, headers) {
|
||||||
|
this.check(payload, headers);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPBinary02.prototype.emit = function(cloudevent){
|
HTTPBinary02.prototype.emit = function(cloudevent){
|
||||||
|
|
Loading…
Reference in New Issue