From 2131ddad6d8e72f01aa4cdd08058ab242bd0b0af Mon Sep 17 00:00:00 2001 From: aks- Date: Sat, 31 Oct 2015 22:35:45 +0530 Subject: [PATCH] http: check callback type of imcoming timeout --- lib/_http_incoming.js | 5 ++++- test/parallel/test-http-client-timeout-event.js | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 5377c84d5d3c7e..371a3bce763872 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -63,8 +63,11 @@ exports.IncomingMessage = IncomingMessage; IncomingMessage.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); + } this.socket.setTimeout(msecs); return this; }; diff --git a/test/parallel/test-http-client-timeout-event.js b/test/parallel/test-http-client-timeout-event.js index c9d65941923408..c4b92efd3e1a3d 100644 --- a/test/parallel/test-http-client-timeout-event.js +++ b/test/parallel/test-http-client-timeout-event.js @@ -2,6 +2,7 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); +var IncomingMessage = http.IncomingMessage; var options = { method: 'GET', @@ -38,3 +39,9 @@ server.listen(options.port, options.host, function() { req.end(); }, 50); }); + +var incomingMessage = new IncomingMessage(server.socket); + +assert.throws(function() { + incomingMessage.setTimeout(1, {}); +});