undici 4.12.0 → 4.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ const {
9
9
  kNeedDrain,
10
10
  kAddClient,
11
11
  kRemoveClient,
12
- kDispatch
12
+ kGetDispatcher
13
13
  } = require('./pool-base')
14
14
  const Pool = require('./pool')
15
15
  const { kUrl } = require('./core/symbols')
@@ -65,7 +65,7 @@ class BalancedPool extends PoolBase {
65
65
  .map((p) => p[kUrl].origin)
66
66
  }
67
67
 
68
- [kDispatch] () {
68
+ [kGetDispatcher] () {
69
69
  // We validate that pools is greater than 0,
70
70
  // otherwise we would have to wait until an upstream
71
71
  // is added, which might never happen.
package/lib/client.js CHANGED
@@ -1016,7 +1016,7 @@ function onParserTimeout (parser) {
1016
1016
  }
1017
1017
  }
1018
1018
 
1019
- function onSocketReadable (data) {
1019
+ function onSocketReadable () {
1020
1020
  const { [kParser]: parser } = this
1021
1021
  parser.readMore()
1022
1022
  }
package/lib/core/util.js CHANGED
@@ -263,7 +263,11 @@ function isErrored (body) {
263
263
  }
264
264
 
265
265
  function isReadable (body) {
266
- return !!(body && /state: 'readable'/.test(nodeUtil.inspect(body)))
266
+ return !!(body && (
267
+ stream.isReadable
268
+ ? stream.isReadable(body)
269
+ : /state: 'readable'/.test(nodeUtil.inspect(body)
270
+ )))
267
271
  }
268
272
 
269
273
  function getSocketInfo (socket) {
@@ -46,6 +46,7 @@ const { kHeadersList } = require('../core/symbols')
46
46
  const EE = require('events')
47
47
  const { PassThrough, pipeline } = require('stream')
48
48
  const { isErrored, isReadable } = require('../core/util')
49
+ const { kIsMockActive } = require('../mock/mock-symbols')
49
50
 
50
51
  let ReadableStream
51
52
 
@@ -1621,7 +1622,7 @@ function httpNetworkFetch (
1621
1622
  path: url.pathname + url.search,
1622
1623
  origin: url.origin,
1623
1624
  method: request.method,
1624
- body,
1625
+ body: context.dispatcher[kIsMockActive] ? request.body && request.body.source : body,
1625
1626
  headers: request.headersList,
1626
1627
  maxRedirections: 0
1627
1628
  },
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { MockNotMatchedError } = require('./mock-errors')
4
+ const { kHeadersList } = require('../core/symbols')
4
5
  const {
5
6
  kDispatches,
6
7
  kMockAgent,
@@ -30,8 +31,11 @@ function matchHeaders (mockDispatch, headers) {
30
31
  if (typeof headers !== 'object' || typeof mockDispatch.headers !== 'object') {
31
32
  return false
32
33
  }
34
+
33
35
  for (const [matchHeaderName, matchHeaderValue] of Object.entries(mockDispatch.headers)) {
34
- if (!matchValue(matchHeaderValue, headers[matchHeaderName])) {
36
+ const header = typeof headers.get === 'function' ? headers.get(matchHeaderName) : headers[matchHeaderName]
37
+
38
+ if (!matchValue(matchHeaderValue, header)) {
35
39
  return false
36
40
  }
37
41
  }
package/lib/pool-base.js CHANGED
@@ -20,7 +20,7 @@ const kOnConnect = Symbol('onConnect')
20
20
  const kOnDisconnect = Symbol('onDisconnect')
21
21
  const kOnConnectionError = Symbol('onConnectionError')
22
22
  const kQueued = Symbol('queued')
23
- const kDispatch = Symbol('dispatch')
23
+ const kGetDispatcher = Symbol('get dispatcher')
24
24
  const kAddClient = Symbol('add client')
25
25
  const kRemoveClient = Symbol('remove client')
26
26
 
@@ -190,7 +190,7 @@ class PoolBase extends Dispatcher {
190
190
  throw new ClientClosedError()
191
191
  }
192
192
 
193
- const dispatcher = this[kDispatch]()
193
+ const dispatcher = this[kGetDispatcher]()
194
194
 
195
195
  if (!dispatcher) {
196
196
  this[kNeedDrain] = true
@@ -198,11 +198,7 @@ class PoolBase extends Dispatcher {
198
198
  this[kQueued]++
199
199
  } else if (!dispatcher.dispatch(opts, handler)) {
200
200
  dispatcher[kNeedDrain] = true
201
- this[kNeedDrain] = this[kClients].some(dispatcher => (
202
- !dispatcher[kNeedDrain] &&
203
- dispatcher.closed !== true &&
204
- dispatcher.destroyed !== true
205
- ))
201
+ this[kNeedDrain] = !this[kGetDispatcher]()
206
202
  }
207
203
  } catch (err) {
208
204
  if (typeof handler.onError !== 'function') {
@@ -257,5 +253,5 @@ module.exports = {
257
253
  kNeedDrain,
258
254
  kAddClient,
259
255
  kRemoveClient,
260
- kDispatch
256
+ kGetDispatcher
261
257
  }
package/lib/pool.js CHANGED
@@ -5,7 +5,7 @@ const {
5
5
  kClients,
6
6
  kNeedDrain,
7
7
  kAddClient,
8
- kDispatch
8
+ kGetDispatcher
9
9
  } = require('./pool-base')
10
10
  const Client = require('./client')
11
11
  const {
@@ -64,7 +64,7 @@ class Pool extends PoolBase {
64
64
  this[kFactory] = factory
65
65
  }
66
66
 
67
- [kDispatch] () {
67
+ [kGetDispatcher] () {
68
68
  let dispatcher = this[kClients].find(dispatcher => !dispatcher[kNeedDrain])
69
69
 
70
70
  if (dispatcher) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "4.12.0",
3
+ "version": "4.12.1",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {