From 0094a8dad725e7b7a035d7c56332844cb105cba3 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 27 Sep 2015 11:54:57 -0700 Subject: [PATCH] http: add callback is function check We were checking that the callback existed, but not checking that it was a function. In `setTimeout`, if callback is truthy but not a function, throw a TypeError Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Ben Noordhuis PR-URL: https://github.com/nodejs/node/pull/3090 --- lib/_http_outgoing.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index dde832ee072427..283a5ab824b19f 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -89,8 +89,12 @@ exports.OutgoingMessage = OutgoingMessage; OutgoingMessage.prototype.setTimeout = function(msecs, callback) { - if (callback) + + if (callback) { + if (typeof callback !== 'function') + throw new TypeError('callback must be a function'); this.on('timeout', callback); + } if (!this.socket) { this.once('socket', function(socket) {