forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: change OutgoingMessage so that it inherits from stream.Writable…
… instead of stream http.OutgoingMessage is supposed to be an instance of stream.Writable, so I set the prototype of OutgoingMessage equal to the Writable prototype and I called the Writable consrtuctor at the end of the constructor for OutgoingMessage. I made sure to override any methods and prpoperties in Writable that were already defined in OutgoingMessage in order to not interfere with the current behavior of OutgoingMessage. Fixes: nodejs#44188
- Loading branch information
1 parent
b3bf07e
commit 7f40107
Showing
5 changed files
with
78 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
cd ~/node/test/parallel | ||
|
||
mkdir test-stream-writable-dir | ||
|
||
for file in ./*.js | ||
do | ||
if [[ "$file" =~ .*"test-stream-writable".* ]]; then | ||
cp $file "./test-stream-writable-dir/$file" | ||
echo "{$file} copied" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const { stream, Writable } = require('stream'); | ||
const { once } = require('events'); | ||
|
||
async function test() { | ||
const o = new http.OutgoingMessage(); | ||
assert.strictEqual(o instanceof http.OutgoingMessage, true); | ||
assert.strictEqual(o instanceof Writable, true); | ||
|
||
let external; | ||
|
||
const server = http.createServer(async (req, nodeStreamResponse) => { | ||
const isOutgoingMessage = nodeStreamResponse instanceof http.OutgoingMessage; | ||
//const isStream = stream.isInstance(nodeStreamResponse); | ||
const isWritable = nodeStreamResponse instanceof Writable; | ||
|
||
assert.strictEqual(nodeStreamResponse.writable, true); | ||
assert.strictEqual(isOutgoingMessage, true); | ||
assert.strictEqual(isWritable, true); | ||
|
||
|
||
const b = typeof nodeStreamResponse?._writableState | ||
|
||
assert.strictEqual(b, 'object') | ||
|
||
const webStreamResponse = Writable.toWeb(nodeStreamResponse); | ||
|
||
setImmediate(common.mustCall(() => { | ||
external.abort(); | ||
nodeStreamResponse.end('Hello World\n'); | ||
})); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
external = http.get(`http://127.0.0.1:${server.address().port}`); | ||
external.on('error', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); | ||
} | ||
|
||
test(); |