Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,8 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
return ret;
};

const outgoingMessagePrototypeWrite = OutgoingMessage.prototype.write;

function onError(msg, err, callback) {
if (msg.destroyed) {
return;
Expand Down Expand Up @@ -1260,4 +1262,5 @@ module.exports = {
validateHeaderName,
validateHeaderValue,
OutgoingMessage,
outgoingMessagePrototypeWrite,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why expose this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Web Streams adapter uses this export to compare the active write() method with the original OutgoingMessage.prototype.write.
This distinction preserves the native validation behavior without applying it to overridden write() implementations.
The reference is captured here so a later prototype monkey-patch is not mistaken for the original method.

};
1 change: 1 addition & 0 deletions lib/internal/streams/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ module.exports = {
isWritableEnded,
isWritableFinished,
isWritableErrored,
isOutgoingMessage,
isServerRequest,
isServerResponse,
willEmitClose,
Expand Down
8 changes: 7 additions & 1 deletion lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ Writable.prototype.write = function(chunk, encoding, cb) {
return _write(this, chunk, encoding, cb) === true;
};

const writablePrototypeWrite = Writable.prototype.write;

Writable.prototype.cork = function() {
const state = this._writableState;

Expand Down Expand Up @@ -1150,7 +1152,11 @@ Writable.fromWeb = function(writableStream, options) {
};

Writable.toWeb = function(streamWritable) {
return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);
return lazyWebStreams().newWritableStreamFromStreamWritable(
streamWritable,
undefined,
writablePrototypeWrite,
);
};

Writable.prototype[SymbolAsyncDispose] = async function() {
Expand Down
Loading
Loading