From 334f8555600b3dd4a2c875914124a0bbb9547613 Mon Sep 17 00:00:00 2001 From: Bryan English Date: Sun, 14 Aug 2016 14:24:05 -0700 Subject: [PATCH] http: fix legacy http.Client instanceof Ensures that objects created with http.createClient() have http.Client.prototype as their prototype. --- lib/http.js | 5 ++++- test/parallel/test-http-legacy.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 64788dd5c07f9f..c9ce680136ae87 100644 --- a/lib/http.js +++ b/lib/http.js @@ -95,5 +95,8 @@ Client.prototype.request = function(method, path, headers) { exports.Client = internalUtil.deprecate(Client, 'http.Client is deprecated.'); exports.createClient = internalUtil.deprecate(function(port, host) { - return new Client(port, host); + const client = new Client(port, host); + // Need to set the prototype of the deprecated class to fix `instanceof`. + Object.setPrototypeOf(client, exports.Client.prototype); + return client; }, 'http.createClient is deprecated. Use http.request instead.'); diff --git a/test/parallel/test-http-legacy.js b/test/parallel/test-http-legacy.js index 36165954cb8f8f..9ae7a79664b3ab 100644 --- a/test/parallel/test-http-legacy.js +++ b/test/parallel/test-http-legacy.js @@ -38,6 +38,7 @@ var server = http.createServer(function(req, res) { server.listen(0, common.mustCall(function() { var client = http.createClient(this.address().port); + assert(client instanceof http.Client); var req = client.request('/hello', {'Accept': '*/*', 'Foo': 'bar'}); setTimeout(function() { req.end();