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