Normalize headers values for pubsub
This commit is contained in:
@@ -38,7 +38,7 @@ module.exports = function errorMiddleware (/* options */) {
|
||||
res.json(errorResponseBody);
|
||||
}
|
||||
|
||||
next();
|
||||
return next();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const EVENT_VERSION = '1';
|
||||
const MAX_LENGTH = 100;
|
||||
|
||||
function pubSubMetrics (pubSubMetricsBackend) {
|
||||
if (!pubSubMetricsBackend.isEnabled()) {
|
||||
@@ -19,9 +20,9 @@ function pubSubMetrics (pubSubMetricsBackend) {
|
||||
}
|
||||
|
||||
function getEventData (req, res) {
|
||||
const event = req.get('Carto-Event');
|
||||
const eventSource = req.get('Carto-Event-Source');
|
||||
const eventGroupId = req.get('Carto-Event-Group-Id');
|
||||
const event = normalizedField(req.get('Carto-Event'));
|
||||
const eventSource = normalizedField(req.get('Carto-Event-Source'));
|
||||
const eventGroupId = normalizedField(req.get('Carto-Event-Group-Id'));
|
||||
|
||||
if (!event || !eventSource) {
|
||||
return [undefined, undefined];
|
||||
@@ -43,4 +44,8 @@ function getEventData (req, res) {
|
||||
return { event, attributes };
|
||||
}
|
||||
|
||||
function normalizedField (field) {
|
||||
return field.toString().substr(0, MAX_LENGTH);
|
||||
}
|
||||
|
||||
module.exports = pubSubMetrics;
|
||||
|
||||
Reference in New Issue
Block a user