GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • lib/internal/webstreams
    • adapters.js
  • test/parallel
    • test-stream-toWeb-allows-server-response.js
Expand file treeCollapse file tree
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

‎test/parallel/test-stream-toWeb-allows-server-response.js‎

Copy file name to clipboard
+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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.