Skip to content

Commit

Permalink
add_response_header_procesing_time
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Sep 23, 2024
1 parent fcc5c03 commit a557e27
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- ADD: reponse header about procesing time (iotagent-node-lib#1650)
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- ADD: reponse header about procesing time (iotagent-node-lib#1650)

3.6.0 (September 18th, 2024)

- Upgrade express from 4.19.2 to 4.20.0 due to a vulnerability
Expand Down
8 changes: 8 additions & 0 deletions lib/bindings/HTTPBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ let context = {
op: 'IOTAUL.HTTP.Binding'
};

function reqTiming(req, res, next) {
req.startTime = Date.now();
next();
}

/* eslint-disable-next-line no-unused-vars */
function handleError(error, req, res, next) {
let code = 500;
Expand Down Expand Up @@ -198,6 +203,7 @@ function returnCommands(req, res, next) {

if (req.query && req.query.getCmd === '1') {
iotAgentLib.commandQueue(req.device.service, req.device.subservice, req.deviceId, function (error, list) {
res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms ');
if (error || !list || list.count === 0) {
res.set('Content-Type', 'text/plain');
res.status(200).send('');
Expand All @@ -209,6 +215,7 @@ function returnCommands(req, res, next) {
});
} else {
res.set('Content-Type', 'text/plain');
res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms ');
res.status(200).send('');
}
}
Expand Down Expand Up @@ -477,6 +484,7 @@ function start(callback) {

httpBindingServer.app.set('port', config.getConfig().http.port);
httpBindingServer.app.set('host', config.getConfig().http.host || '0.0.0.0');
httpBindingServer.app.use(reqTiming);

httpBindingServer.router.get(
config.getConfig().iota.defaultResource || constants.HTTP_MEASURE_PATH,
Expand Down
4 changes: 3 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ module.exports = {
AMQP_DEFAULT_QUEUE: 'iotaqueue',
AMQP_DEFAULT_DURABLE: true,
AMQP_DEFAULT_RETRIES: 5,
AMQP_DEFAULT_RETRY_TIME: 5
AMQP_DEFAULT_RETRY_TIME: 5,

X_PROCESSING_TIME: 'X-Processing-Time'
};

0 comments on commit a557e27

Please sign in to comment.