Skip to content
Open
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
9 changes: 3 additions & 6 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { IncomingMessage } = require('node:http')
const stream = require('node:stream')
const net = require('node:net')
const { stringify } = require('node:querystring')
const { EventEmitter: EE } = require('node:events')
const timers = require('../util/timers')
const { InvalidArgumentError, ConnectTimeoutError } = require('./errors')
const { headerNameLowerCasedRecord } = require('./constants')
Expand Down Expand Up @@ -43,12 +42,10 @@ function wrapRequestBody (body) {
.on('data', function () {
assert(false)
})
}

if (typeof body.readableDidRead !== 'boolean') {
} else if (typeof body.readableDidRead !== 'boolean') {
body[kBodyUsed] = false
EE.prototype.on.call(body, 'data', function () {
this[kBodyUsed] = true
body.once('data', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I believe the initial intention was to avoid tampering, but given that every stream is EE based, it shouldn’t be a problem (bad stream, bad implementation, up to caller).

I’m just more into keep it with this instead of creating another closure; the rest LGTM

Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. It's not because of tampering but because otherwise the stream will start when registering a data listener.

body[kBodyUsed] = true
})
}

Expand Down
Loading