Socket
Socket
Sign inDemoInstall

content-length

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

content-length - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

18

index.js
module.exports = function (done) {
if (!done || typeof done !== 'function') throw new Error('Must provide a callback for content-length');
if (!done || typeof done !== 'function') throw new Error('Must provide a callback for content-length');
return function (req, res, next) {

@@ -8,21 +8,19 @@ var byteLength = 0;

var write = res.write;
res.write = function (payload) {
if (payload) byteLength += Buffer.byteLength(payload.toString(), 'utf8');
res.write = write;
res.write.apply(res, arguments);
};
res.end = function (payload) {
if (payload) byteLength += Buffer.byteLength(payload.toString(), 'utf8');
res.end = end;
res.end.apply(res, arguments);
done(null, byteLength);
};
next();
}
}
}
{
"name": "content-length",
"version": "1.0.0",
"version": "1.0.1",
"description": "Express/Connect middleware to calculate the response payload size",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,11 +10,11 @@ var contentLength = require('../');

var responseLength = 0;
app.use(contentLength(function (err, len) {
responseLength = len;
}));
app.use(function (req, res) {
res.send('Hi');
});
request(app)

@@ -31,15 +31,15 @@ .get('/')

});
it('gives a 0 content length if there is no response', function (done) {
var app = express();
var responseLength = 0;
app.use(contentLength(function (err, len) {
responseLength = len;
}));
app.use(function (req, res) {
res.send();
});
request(app)

@@ -56,6 +56,6 @@ .get('/')

});
it('throws an error if no callback is given', function () {
var app = express();
expect(function () {

@@ -65,6 +65,6 @@ app.use(contentLength());

});
it('throws an error if the callback is not a function', function () {
var app = express();
expect(function () {

@@ -74,2 +74,2 @@ app.use(contentLength('test'));

});
});
});
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