1
0
Fork 0

Validate request headers also

This commit is contained in:
Alan Plum 2016-06-14 16:20:37 +02:00
parent 4466925398
commit 0867e8aa87
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
1 changed files with 21 additions and 0 deletions

View File

@ -209,6 +209,7 @@ function applyPathParams(route) {
function dispatch(route, req, res) {
let pathParams = {};
let queryParams = Object.assign({}, req.queryParams);
let headers = Object.assign({}, req.headers);
{
let basePath = [];
@ -283,8 +284,24 @@ function dispatch(route, req, res) {
}
}
if (context._headers.size) {
try {
item.headers = validation.validateParams(
context._headers,
req.headers,
'header'
);
} catch (e) {
throw Object.assign(
new httperr.BadRequest(e.message),
{cause: e}
);
}
}
let tempPathParams = req.pathParams;
let tempQueryParams = req.queryParams;
let tempHeaders = req.headers;
let tempSuffix = req.suffix;
let tempPath = req.path;
let tempReverse = req.reverse;
@ -353,11 +370,14 @@ function dispatch(route, req, res) {
if (item.endpoint || item.router) {
pathParams = Object.assign(pathParams, item.pathParams);
queryParams = Object.assign(queryParams, item.queryParams);
headers = Object.assign(headers, item.headers);
req.pathParams = pathParams;
req.queryParams = queryParams;
req.headers = headers;
} else {
req.pathParams = Object.assign({}, pathParams, item.pathParams);
req.queryParams = Object.assign({}, queryParams, item.queryParams);
req.headers = Object.assign({}, headers, item.headers);
}
if (!context._handler) {
@ -372,6 +392,7 @@ function dispatch(route, req, res) {
req.reverse = tempReverse;
req.path = tempPath;
req.suffix = tempSuffix;
req.headers = tempHeaders;
req.queryParams = tempQueryParams;
req.pathParams = tempPathParams;
}