From cac599276bc1eabfb13f42787781a2c776485a2e Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Tue, 6 Nov 2018 15:24:26 +0000 Subject: [PATCH 1/2] http: change DEP0066 to a runtime deprecation Change doc-only deprecation for _headers and _headerNames accessors to a runtime deprecation. PR-URL: https://github.com/nodejs/node/pull/24167 Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat Reviewed-By: Matteo Collina Reviewed-By: Anatoli Papirovski --- doc/api/deprecations.md | 5 ++++- lib/_http_outgoing.js | 16 +++++++------- ...test-http-outgoing-internal-headernames.js | 21 +++++++++++++++++++ .../test-http-outgoing-internal-headers.js | 3 +++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 test/parallel/test-http-outgoing-internal-headernames.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 5051b71a5a7d99..910606e4f79f51 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -1344,12 +1344,15 @@ removed. Please use `sloppy` instead. ### DEP0066: outgoingMessage.\_headers, outgoingMessage.\_headerNames -Type: Documentation-only +Type: Runtime The `http` module `outgoingMessage._headers` and `outgoingMessage._headerNames` properties are deprecated. Use one of the public methods diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 04a36d2be2fde3..3bedce9d515b38 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -110,10 +110,10 @@ util.inherits(OutgoingMessage, Stream); Object.defineProperty(OutgoingMessage.prototype, '_headers', { - get: function() { + get: util.deprecate(function() { return this.getHeaders(); - }, - set: function(val) { + }, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'), + set: util.deprecate(function(val) { if (val == null) { this[outHeadersKey] = null; } else if (typeof val === 'object') { @@ -124,11 +124,11 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', { headers[name.toLowerCase()] = [name, val[name]]; } } - } + }, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066') }); Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { - get: function() { + get: util.deprecate(function() { const headers = this[outHeadersKey]; if (headers !== null) { const out = Object.create(null); @@ -141,8 +141,8 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { return out; } return null; - }, - set: function(val) { + }, 'OutgoingMessage.prototype._headerNames is deprecated', 'DEP0066'), + set: util.deprecate(function(val) { if (typeof val === 'object' && val !== null) { const headers = this[outHeadersKey]; if (!headers) @@ -154,7 +154,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { header[0] = val[keys[i]]; } } - } + }, 'OutgoingMessage.prototype._headerNames is deprecated', 'DEP0066') }); diff --git a/test/parallel/test-http-outgoing-internal-headernames.js b/test/parallel/test-http-outgoing-internal-headernames.js new file mode 100644 index 00000000000000..6313f863017b08 --- /dev/null +++ b/test/parallel/test-http-outgoing-internal-headernames.js @@ -0,0 +1,21 @@ +'use strict'; +const common = require('../common'); + +const { OutgoingMessage } = require('http'); + +const warn = 'OutgoingMessage.prototype._headerNames is deprecated'; +common.expectWarning('DeprecationWarning', warn, 'DEP0066'); + +{ + // tests for _headerNames get method + const outgoingMessage = new OutgoingMessage(); + outgoingMessage._headerNames; +} + +{ + // tests for _headerNames set method + const outgoingMessage = new OutgoingMessage(); + outgoingMessage._headerNames = { + 'x-flow-id': '61bba6c5-28a3-4eab-9241-2ecaa6b6a1fd' + }; +} diff --git a/test/parallel/test-http-outgoing-internal-headers.js b/test/parallel/test-http-outgoing-internal-headers.js index de75a44e8a05d7..2cebfe9e2b966a 100644 --- a/test/parallel/test-http-outgoing-internal-headers.js +++ b/test/parallel/test-http-outgoing-internal-headers.js @@ -6,6 +6,9 @@ const assert = require('assert'); const { outHeadersKey } = require('internal/http'); const { OutgoingMessage } = require('http'); +const warn = 'OutgoingMessage.prototype._headers is deprecated'; +common.expectWarning('DeprecationWarning', warn, 'DEP0066'); + { // tests for _headers get method const outgoingMessage = new OutgoingMessage(); From da1210ade62954692ead3bea011f67c236940ff0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 21 Nov 2018 20:46:06 -0800 Subject: [PATCH 2/2] fixup! http: change DEP0066 to a runtime deprecation --- ...est-http-outgoing-internal-headernames-getter.js | 13 +++++++++++++ ...st-http-outgoing-internal-headernames-setter.js} | 6 ------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 test/parallel/test-http-outgoing-internal-headernames-getter.js rename test/parallel/{test-http-outgoing-internal-headernames.js => test-http-outgoing-internal-headernames-setter.js} (76%) diff --git a/test/parallel/test-http-outgoing-internal-headernames-getter.js b/test/parallel/test-http-outgoing-internal-headernames-getter.js new file mode 100644 index 00000000000000..c8bd1f13d5c6e5 --- /dev/null +++ b/test/parallel/test-http-outgoing-internal-headernames-getter.js @@ -0,0 +1,13 @@ +'use strict'; +const common = require('../common'); + +const { OutgoingMessage } = require('http'); + +const warn = 'OutgoingMessage.prototype._headerNames is deprecated'; +common.expectWarning('DeprecationWarning', warn, 'DEP0066'); + +{ + // tests for _headerNames get method + const outgoingMessage = new OutgoingMessage(); + outgoingMessage._headerNames; +} diff --git a/test/parallel/test-http-outgoing-internal-headernames.js b/test/parallel/test-http-outgoing-internal-headernames-setter.js similarity index 76% rename from test/parallel/test-http-outgoing-internal-headernames.js rename to test/parallel/test-http-outgoing-internal-headernames-setter.js index 6313f863017b08..73290766983368 100644 --- a/test/parallel/test-http-outgoing-internal-headernames.js +++ b/test/parallel/test-http-outgoing-internal-headernames-setter.js @@ -6,12 +6,6 @@ const { OutgoingMessage } = require('http'); const warn = 'OutgoingMessage.prototype._headerNames is deprecated'; common.expectWarning('DeprecationWarning', warn, 'DEP0066'); -{ - // tests for _headerNames get method - const outgoingMessage = new OutgoingMessage(); - outgoingMessage._headerNames; -} - { // tests for _headerNames set method const outgoingMessage = new OutgoingMessage();