GeezerVison is showing github.com — lib: allow Writeable.toWeb() to work on http.Outgoing message · nodejs/node@bbaca84
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,11 +101,17 @@ function newWritableStreamFromStreamWritable(streamWritable) { |
101 | 101 | // here because it will return false if streamWritable is a Duplex |
102 | 102 | // whose writable option is false. For a Duplex that is not writable, |
103 | 103 | // 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) { |
105 | 110 | throw new ERR_INVALID_ARG_TYPE( |
106 | 111 | 'streamWritable', |
107 | 112 | 'stream.Writable', |
108 | | - streamWritable); |
| 113 | + streamWritable |
| 114 | + ); |
109 | 115 | } |
110 | 116 |
|
111 | 117 | if (isDestroyed(streamWritable) || !isWritable(streamWritable)) { |
|
Collapse file
Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +); |