From 36dd564690fbcb61c032b858ebf7f3cfbea86bba Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 13 Feb 2017 12:26:52 -0800 Subject: [PATCH] http: deprecate Agent.prototype.addRequest() legacy sig The legacy signature of Agent.prototype.addRequest() was replaced four years ago. This emits a runtime deprecation if the legacy signature is used. A potentially deoptimizing use of arguments is also fixed. Ref: https://github.com/nodejs/node/commit/12cd13312b1bd1ea1642c0058bbc14be72c347f0 --- doc/api/deprecations.md | 6 ++++++ lib/_http_agent.js | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 1549d49872a4..ce5ce331d7fe 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -523,6 +523,12 @@ Type: Runtime of V8 5.8. It is replaced by Inspector which is activated with `--inspect` instead. +### DEP0063: http.Agent.prototype.addRequest() Legacy API + +The legacy `http.Agent.prototype.addRequest(req, host, port, localAddress)` +variation has been deprecated in favor of +`http.Agent.prototype.addRequest(req, options)`. + [alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding [alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size diff --git a/lib/_http_agent.js b/lib/_http_agent.js index eebdb242463b..b295844c2a56 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -110,13 +110,18 @@ Agent.prototype.getName = function getName(options) { return name; }; -Agent.prototype.addRequest = function addRequest(req, options) { +Agent.prototype.addRequest = function addRequest(req, options, + port, localAddress) { // Legacy API: addRequest(req, host, port, localAddress) if (typeof options === 'string') { + process.emitWarning( + 'The Agent.prototype.addRequest(req, host, port, localAddress) ' + + 'API has been deprecated. Please use Agent.prototype.addRequest(' + + 'req, options) instead.', 'DeprecationWarning', 'DEP0063'); options = { host: options, - port: arguments[2], - localAddress: arguments[3] + port: port, + localAddress: localAddress }; }