undici 7.5.0 → 7.6.0

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Extends: `undici.Dispatcher`
4
4
 
5
- Agent allow dispatching requests against multiple different origins.
5
+ Agent allows dispatching requests against multiple different origins.
6
6
 
7
7
  Requests are not guaranteed to be dispatched in order of invocation.
8
8
 
package/lib/core/util.js CHANGED
@@ -13,7 +13,7 @@ const { InvalidArgumentError } = require('./errors')
13
13
  const { headerNameLowerCasedRecord } = require('./constants')
14
14
  const { tree } = require('./tree')
15
15
 
16
- const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(v))
16
+ const [nodeMajor, nodeMinor] = process.versions.node.split('.', 2).map(v => Number(v))
17
17
 
18
18
  class BodyAsyncIterable {
19
19
  constructor (body) {
@@ -9,7 +9,7 @@ const assert = require('node:assert')
9
9
  * here, which we then just pass on to the next handler (most likely a
10
10
  * CacheHandler). Note that this assumes the proper headers were already
11
11
  * included in the request to tell the origin that we want to revalidate the
12
- * response (i.e. if-modified-since).
12
+ * response (i.e. if-modified-since or if-none-match).
13
13
  *
14
14
  * @see https://www.rfc-editor.org/rfc/rfc9111.html#name-validation
15
15
  *
@@ -6,7 +6,7 @@ const util = require('../core/util')
6
6
  const CacheHandler = require('../handler/cache-handler')
7
7
  const MemoryCacheStore = require('../cache/memory-cache-store')
8
8
  const CacheRevalidationHandler = require('../handler/cache-revalidation-handler')
9
- const { assertCacheStore, assertCacheMethods, makeCacheKey, parseCacheControlHeader } = require('../util/cache.js')
9
+ const { assertCacheStore, assertCacheMethods, makeCacheKey, normaliseHeaders, parseCacheControlHeader } = require('../util/cache.js')
10
10
  const { AbortError } = require('../core/errors.js')
11
11
 
12
12
  /**
@@ -221,7 +221,7 @@ function handleResult (
221
221
  // Check if the response is stale
222
222
  if (needsRevalidation(result, reqCacheControl)) {
223
223
  if (util.isStream(opts.body) && util.bodyLength(opts.body) !== 0) {
224
- // If body is is stream we can't revalidate...
224
+ // If body is a stream we can't revalidate...
225
225
  // TODO (fix): This could be less strict...
226
226
  return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler))
227
227
  }
@@ -233,7 +233,7 @@ function handleResult (
233
233
  }
234
234
 
235
235
  let headers = {
236
- ...opts.headers,
236
+ ...normaliseHeaders(opts),
237
237
  'if-modified-since': new Date(result.cachedAt).toUTCString()
238
238
  }
239
239
 
@@ -97,7 +97,7 @@ function safeUrl (path) {
97
97
  return path
98
98
  }
99
99
 
100
- const pathSegments = path.split('?')
100
+ const pathSegments = path.split('?', 3)
101
101
 
102
102
  if (pathSegments.length !== 2) {
103
103
  return path
package/lib/util/cache.js CHANGED
@@ -12,7 +12,21 @@ function makeCacheKey (opts) {
12
12
  throw new Error('opts.origin is undefined')
13
13
  }
14
14
 
15
- /** @type {Record<string, string[] | string>} */
15
+ const headers = normaliseHeaders(opts)
16
+
17
+ return {
18
+ origin: opts.origin.toString(),
19
+ method: opts.method,
20
+ path: opts.path,
21
+ headers
22
+ }
23
+ }
24
+
25
+ /**
26
+ * @param {Record<string, string[] | string>}
27
+ * @return {Record<string, string[] | string>}
28
+ */
29
+ function normaliseHeaders (opts) {
16
30
  let headers
17
31
  if (opts.headers == null) {
18
32
  headers = {}
@@ -38,12 +52,7 @@ function makeCacheKey (opts) {
38
52
  throw new Error('opts.headers is not an object')
39
53
  }
40
54
 
41
- return {
42
- origin: opts.origin.toString(),
43
- method: opts.method,
44
- path: opts.path,
45
- headers
46
- }
55
+ return headers
47
56
  }
48
57
 
49
58
  /**
@@ -350,6 +359,7 @@ function assertCacheMethods (methods, name = 'CacheMethods') {
350
359
 
351
360
  module.exports = {
352
361
  makeCacheKey,
362
+ normaliseHeaders,
353
363
  assertCacheKey,
354
364
  assertCacheValue,
355
365
  parseCacheControlHeader,
@@ -309,7 +309,9 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
309
309
  originalURL.href,
310
310
  initiatorType,
311
311
  globalThis,
312
- cacheState
312
+ cacheState,
313
+ '', // bodyType
314
+ response.status
313
315
  )
314
316
  }
315
317
 
@@ -994,7 +996,7 @@ function fetchFinale (fetchParams, response) {
994
996
  // 3. Set fetchParams’s controller’s report timing steps to the following steps given a global object global:
995
997
  fetchParams.controller.reportTimingSteps = () => {
996
998
  // 1. If fetchParams’s request’s URL’s scheme is not an HTTP(S) scheme, then return.
997
- if (fetchParams.request.url.protocol !== 'https:') {
999
+ if (!urlIsHttpHttpsScheme(fetchParams.request.url)) {
998
1000
  return
999
1001
  }
1000
1002
 
@@ -1036,7 +1038,6 @@ function fetchFinale (fetchParams, response) {
1036
1038
  // fetchParams’s request’s URL, fetchParams’s request’s initiator type, global, cacheState, bodyInfo,
1037
1039
  // and responseStatus.
1038
1040
  if (fetchParams.request.initiatorType != null) {
1039
- // TODO: update markresourcetiming
1040
1041
  markResourceTiming(timingInfo, fetchParams.request.url.href, fetchParams.request.initiatorType, globalThis, cacheState, bodyInfo, responseStatus)
1041
1042
  }
1042
1043
  }
@@ -206,7 +206,7 @@ function parseExtensions (extensions) {
206
206
 
207
207
  while (position.position < extensions.length) {
208
208
  const pair = collectASequenceOfCodePointsFast(';', extensions, position)
209
- const [name, value = ''] = pair.split('=')
209
+ const [name, value = ''] = pair.split('=', 2)
210
210
 
211
211
  extensionList.set(
212
212
  removeHTTPWhitespace(name, true, false),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "7.5.0",
3
+ "version": "7.6.0",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {
@@ -108,7 +108,7 @@
108
108
  },
109
109
  "devDependencies": {
110
110
  "@fastify/busboy": "3.1.1",
111
- "@matteo.collina/tspl": "^0.1.1",
111
+ "@matteo.collina/tspl": "^0.2.0",
112
112
  "@sinonjs/fake-timers": "^12.0.0",
113
113
  "@types/node": "^18.19.50",
114
114
  "abort-controller": "^3.0.0",