Socket
Socket
Sign inDemoInstall

request-stats

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-stats - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

47

index.js

@@ -6,2 +6,3 @@ 'use strict';

var EventEmitter = require('events').EventEmitter;
var once = require('once');
var httpHeaders = require('http-headers');

@@ -19,30 +20,32 @@

var toMilliseconds = function (tuple) {
return Math.round(tuple[0] * 1000 + tuple[1] / 1000000);
};
StatsEmitter.prototype._request = function (req, res, onStats) {
var that = this;
var start = new Date();
var start = process.hrtime();
this._attach(onStats);
var emit = function (ok) {
return function () {
that.emit('stats', {
ok : ok,
time : new Date() - start,
req : {
bytes : req.connection.bytesRead,
headers : req.headers,
method : req.method,
path : req.url
},
res : {
bytes : req.connection.bytesWritten,
headers : httpHeaders(res),
status : res.statusCode
}
});
};
};
var emit = once(function (ok) {
that.emit('stats', {
ok : ok,
time : toMilliseconds(process.hrtime(start)),
req : {
bytes : req.connection.bytesRead,
headers : req.headers,
method : req.method,
path : req.url
},
res : {
bytes : req.connection.bytesWritten,
headers : httpHeaders(res),
status : res.statusCode
}
});
});
res.once('finish', emit(true));
res.once('close', emit(false));
res.once('finish', emit.bind(null, true));
res.once('close', emit.bind(null, false));
};

@@ -49,0 +52,0 @@

{
"name": "request-stats",
"version": "0.3.0",
"version": "0.3.1",
"description": "Get stats on your Node.js HTTP server requests",

@@ -30,3 +30,4 @@ "main": "index.js",

"dependencies": {
"http-headers": "0.1.x"
"http-headers": "0.1.x",
"once": "1.3.x"
},

@@ -33,0 +34,0 @@ "devDependencies": {

@@ -9,3 +9,3 @@ 'use strict';

assert(stats.ok);
assert(stats.time >= 9); // setTimeout isn't that precise, so we use 9 instead of 10 to be on the safe side
assert(stats.time >= 9); // The reason we don't just do >= 10, is because setTimeout is not that precise
assert(stats.req.bytes > 0); // different headers will result in different results

@@ -12,0 +12,0 @@ assert.equal(typeof stats.req.headers.connection, 'string');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc