From d24625964042030a6bda53f3f8368dffbe604606 Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Sun, 27 Nov 2022 13:59:17 +0530 Subject: [PATCH] src: allow Writeable.toWeb() to work on http.Outgoing message Attempted to fix the issue by watering down the condition being checked in lib/internal/webstreams/adapters.js similar to isWritableNodeStream utility being used in internal/streams/utils Fixes: /~https://github.com/nodejs/node/issues/44188 --- lib/internal/webstreams/adapters.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index 0e844d01200751..7e2ba628ac8889 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -101,11 +101,17 @@ function newWritableStreamFromStreamWritable(streamWritable) { // here because it will return false if streamWritable is a Duplex // whose writable option is false. For a Duplex that is not writable, // we want it to pass this check but return a closed WritableStream. - if (typeof streamWritable?._writableState !== 'object') { + const checkIfWritable = + streamWritable && + typeof streamWritable?.write === 'function' && + typeof streamWritable?.on === 'function' && + !streamWritable?._readableState; + if (!checkIfWritable) { throw new ERR_INVALID_ARG_TYPE( 'streamWritable', 'stream.Writable', - streamWritable); + streamWritable + ); } if (isDestroyed(streamWritable) || !isWritable(streamWritable)) {