From 4e40ea8630499111ed46473472751c6e6d60c722 Mon Sep 17 00:00:00 2001 From: Xmader Date: Tue, 4 Jun 2019 01:34:49 -0400 Subject: [PATCH 1/4] support for Node.js 12 --- lib/response-stream.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/response-stream.js b/lib/response-stream.js index e11b2d3..44575a8 100644 --- a/lib/response-stream.js +++ b/lib/response-stream.js @@ -47,10 +47,7 @@ var ResponseStream = module.exports = function (options) { }); if (this.response) { - this._headers = this.response._headers = this.response._headers || {}; - - // Patch to node core - this.response._headerNames = this.response._headerNames || {}; + this._headers = this.response.getHeaders() || {}; // // Proxy to emit "header" event From b3299a87020f85ca7122cf478f54ad711da2be25 Mon Sep 17 00:00:00 2001 From: Xmader Date: Tue, 4 Jun 2019 16:26:05 -0400 Subject: [PATCH 2/4] Backward compatible --- lib/response-stream.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/response-stream.js b/lib/response-stream.js index 44575a8..1efa5ce 100644 --- a/lib/response-stream.js +++ b/lib/response-stream.js @@ -47,7 +47,15 @@ var ResponseStream = module.exports = function (options) { }); if (this.response) { - this._headers = this.response.getHeaders() || {}; + + try { + this._headers = this.response.getHeaders() || {}; + } catch (err) { + this._headers = this.response._headers = this.response._headers || {}; + + // Patch to node core + this.response._headerNames = this.response._headerNames || {}; + } // // Proxy to emit "header" event From e2610d903925d54ae147257f00d196a5451b4eb6 Mon Sep 17 00:00:00 2001 From: darrendatbui <152910925+darrendatbui@users.noreply.github.com> Date: Sun, 14 Jan 2024 18:25:13 +1100 Subject: [PATCH 3/4] Update response-stream.js Fix missing cases --- lib/response-stream.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/response-stream.js b/lib/response-stream.js index 1efa5ce..8ef89a1 100644 --- a/lib/response-stream.js +++ b/lib/response-stream.js @@ -52,8 +52,12 @@ var ResponseStream = module.exports = function (options) { this._headers = this.response.getHeaders() || {}; } catch (err) { this._headers = this.response._headers = this.response._headers || {}; + } - // Patch to node core + // Patch to node core + try { + this.response._headerNames = this.response.getHeaderNames() || {}; + } catch (err) { this.response._headerNames = this.response._headerNames || {}; } From 1ffd71181f39ff01c39d48f680a48394fba8b442 Mon Sep 17 00:00:00 2001 From: darrendatbui <152910925+darrendatbui@users.noreply.github.com> Date: Mon, 15 Jan 2024 17:59:40 +1100 Subject: [PATCH 4/4] Update response-stream.js Fix OutgoingMessage.prototype._headerNames is deprecated but it still used in newer version --- lib/response-stream.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/response-stream.js b/lib/response-stream.js index 8ef89a1..c682b5d 100644 --- a/lib/response-stream.js +++ b/lib/response-stream.js @@ -51,14 +51,10 @@ var ResponseStream = module.exports = function (options) { try { this._headers = this.response.getHeaders() || {}; } catch (err) { + // OutgoingMessage.prototype._headers is deprecated. The following code maintains backward compatibility. this._headers = this.response._headers = this.response._headers || {}; - } - - // Patch to node core - try { - this.response._headerNames = this.response.getHeaderNames() || {}; - } catch (err) { - this.response._headerNames = this.response._headerNames || {}; + // OutgoingMessage.prototype._headerNames is deprecated. The following code maintains backward compatibility. No need to set for newer version as it is unsettable. Patch to node core. + this.response._headerNames = this.response._headerNames || {}; } //