Skip to content

Commit

Permalink
fixup: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 30, 2021
1 parent ba51fe5 commit 7334d8c
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ The `RequestOptions.method` property should not be value `'CONNECT'`.

* **statusCode** `number`
* **headers** `http.IncomingHttpHeaders`
* **body** `stream.Readable`
* **body** `stream.Readable` which also implements [the body mixin from the Fetch Standard](https://fetch.spec.whatwg.org/#body-mixin).
* **trailers** `Record<string, string>` - This object starts out
as empty and will be mutated to contain trailers after `body` has emitted `'end'`.
* **opaque** `unknown`
Expand Down
12 changes: 8 additions & 4 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ module.exports = class BodyReadable extends Readable {
return super.on(ev, ...args)
}

addListener (ev, ...args) {
if (ev === 'data' || ev === 'readable') {
this[kReading] = true
}
return super.addListener(ev, ...args)
}

push (chunk, encoding) {
if (this[kConsume] && chunk !== null && !this[kReading]) {
// Fast path.
Expand Down Expand Up @@ -90,6 +97,7 @@ module.exports = class BodyReadable extends Readable {
return isDisturbed(this)
}

// https://fetch.spec.whatwg.org/#dom-body-body
get body () {
if (this[kConsume] && this[kConsume].type === kWebStreamType) {
return this[kConsume].stream
Expand Down Expand Up @@ -125,20 +133,16 @@ function isUnusable (self) {

async function consume (parent, type) {
if (isUnusable(parent)) {
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('unusable')
}

if (parent[kConsume]) {
// TODO: Should multiple consume in same tick be possible?
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('unusable')
}

if (type === kWebStreamType) {
const consume = parent[kConsume] = {
type,
// TODO: Optimized implementation for web streams.
stream: Readable.toWeb(parent)
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undici",
"version": "4.3.0",
"version": "4.2.2",
"description": "An HTTP/1.1 client, written from scratch for Node.js",
"homepage": "https://undici.nodejs.org",
"bugs": {
Expand Down
Loading

0 comments on commit 7334d8c

Please sign in to comment.