Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bbaca84

Browse filesBrowse files
debadree25danielleadams
authored andcommitted
lib: allow Writeable.toWeb() to work on http.Outgoing message
Attempted to fix the issue by watering down the condition being checked in internal/streams/utils isWritableNodeStream utility Fixes: #44188 PR-URL: #45642 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent ff03ed1 commit bbaca84
Copy full SHA for bbaca84

File tree

Expand file treeCollapse file tree

2 files changed

+37
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/webstreams/adapters.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,17 @@ function newWritableStreamFromStreamWritable(streamWritable) {
101101
// here because it will return false if streamWritable is a Duplex
102102
// whose writable option is false. For a Duplex that is not writable,
103103
// we want it to pass this check but return a closed WritableStream.
104-
if (typeof streamWritable?._writableState !== 'object') {
104+
// We check if the given stream is a stream.Writable or http.OutgoingMessage
105+
const checkIfWritableOrOutgoingMessage =
106+
streamWritable &&
107+
typeof streamWritable?.write === 'function' &&
108+
typeof streamWritable?.on === 'function';
109+
if (!checkIfWritableOrOutgoingMessage) {
105110
throw new ERR_INVALID_ARG_TYPE(
106111
'streamWritable',
107112
'stream.Writable',
108-
streamWritable);
113+
streamWritable
114+
);
109115
}
110116

111117
if (isDestroyed(streamWritable) || !isWritable(streamWritable)) {
Collapse file
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { Writable } = require('stream');
4+
5+
const assert = require('assert');
6+
const http = require('http');
7+
8+
// Check if Writable.toWeb works on the response object after creating a server.
9+
const server = http.createServer(
10+
common.mustCall((req, res) => {
11+
const webStreamResponse = Writable.toWeb(res);
12+
assert.strictEqual(webStreamResponse instanceof WritableStream, true);
13+
res.end();
14+
})
15+
);
16+
17+
server.listen(
18+
0,
19+
common.mustCall(() => {
20+
http.get(
21+
{
22+
port: server.address().port,
23+
},
24+
common.mustCall(() => {
25+
server.close();
26+
})
27+
);
28+
})
29+
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.