Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 25, 2022
1 parent 7d1d620 commit 213cbfe
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const assert = require('assert')
const { kDestroyed, kBodyUsed } = require('./symbols')
const { IncomingMessage } = require('http')
const stream = require('stream')
const stream2 = require('readable-stream')
const net = require('net')
const { InvalidArgumentError } = require('./errors')
const { Blob } = require('buffer')
Expand Down Expand Up @@ -278,30 +279,52 @@ function validateHandler (handler, method, upgrade) {
// A body is disturbed if it has been read from and it cannot
// be re-used without losing state or data.
function isDisturbed (body) {
return !!(body && (
stream.isDisturbed
? stream.isDisturbed(body) || body[kBodyUsed] // TODO (fix): Why is body[kBodyUsed] needed?
: body[kBodyUsed] ||
body.readableDidRead ||
(body._readableState && body._readableState.dataEmitted) ||
isReadableAborted(body)
))
if (!body) {
return false
}
if (stream.isDisturbed && stream.isDisturbed(body)) {
return true
}
if (stream2.isDisturbed && stream2.isDisturbed(body)) {
return true
}
if (body[kBodyUsed]) {
return true
}

return !!(
body.readableDidRead ||
(body._readableState && body._readableState.dataEmitted) ||
isReadableAborted(body)
)
}

function isErrored (body) {
return !!(body && (
stream.isErrored
? stream.isErrored(body)
: /state: 'errored'/.test(nodeUtil.inspect(body)
)))
if (!body) {
return false
}
if (stream.isErrored && stream.isErrored(body)) {
return true
}
if (stream2.isErrored && stream2.isErrored(body)) {
return true
}

return /state: 'errored'/.test(nodeUtil.inspect(body))
}

function isReadable (body) {
return !!(body && (
stream.isReadable
? stream.isReadable(body)
: /state: 'readable'/.test(nodeUtil.inspect(body)
)))
if (!body) {
return false
}
if (stream.isReadable && stream.isReadable(body)) {
return true
}
if (stream2.isReadable && stream2.isReadable(body)) {
return true
}

return /state: 'readable'/.test(nodeUtil.inspect(body))
}

function getSocketInfo (socket) {
Expand Down

0 comments on commit 213cbfe

Please sign in to comment.