From 85247a0d8f7fb6ed6a1c74473809c320ec6a63af Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sun, 14 Jun 2020 11:42:02 +0530 Subject: [PATCH] http: make http.OutgoingMessage inherit Stream.Writable Fixes: https://github.com/nodejs/node/issues/28971 --- lib/_http_outgoing.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index dade9a11014c01..4b09f242a23b2a 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -24,6 +24,7 @@ const { ArrayIsArray, ObjectCreate, + ObjectDefineProperties, ObjectDefineProperty, ObjectKeys, ObjectPrototypeHasOwnProperty, @@ -34,7 +35,7 @@ const { const { getDefaultHighWaterMark } = require('internal/streams/state'); const assert = require('internal/assert'); const EE = require('events'); -const Stream = require('stream'); +const { Stream, Writable } = require('stream'); const internalUtil = require('internal/util'); const { kOutHeaders, utcDate, kNeedDrain } = require('internal/http'); const { Buffer } = require('buffer'); @@ -97,8 +98,8 @@ function OutgoingMessage() { // TCP socket and HTTP Parser and thus handle the backpressure. this.outputSize = 0; - this.writable = true; - this.destroyed = false; + this.writableProxy = true; + this.destroyedProxy = false; this._last = false; this.chunkedEncoding = false; @@ -124,8 +125,27 @@ function OutgoingMessage() { this._onPendingData = noopPendingOutput; } -ObjectSetPrototypeOf(OutgoingMessage.prototype, Stream.prototype); -ObjectSetPrototypeOf(OutgoingMessage, Stream); +ObjectSetPrototypeOf(OutgoingMessage.prototype, Writable.prototype); +ObjectSetPrototypeOf(OutgoingMessage, Writable); + +ObjectDefineProperties(OutgoingMessage.prototype, { + writable: { + get() { + return this.writableProxy; + }, + set(val) { + this.writableProxy = !!val; + } + }, + destroyed: { + get() { + return this.destroyedProxy; + }, + set(val) { + this.destroyedProxy = !!val; + } + } +}); ObjectDefineProperty(OutgoingMessage.prototype, 'writableFinished', { get() {