@nxtedition/nxt-undici 4.2.2 → 4.2.4
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.
- package/lib/index.js +3 -2
- package/lib/interceptor/dns.js +7 -3
- package/lib/utils.js +87 -10
- package/package.json +10 -10
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import undici from '
|
|
1
|
+
import undici from 'undici'
|
|
2
2
|
import { parseHeaders } from './utils.js'
|
|
3
3
|
|
|
4
4
|
const dispatcherCache = new WeakMap()
|
|
@@ -18,7 +18,7 @@ export const interceptors = {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export { parseHeaders } from './utils.js'
|
|
21
|
-
export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from '
|
|
21
|
+
export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from 'undici'
|
|
22
22
|
|
|
23
23
|
function wrapDispatcher(dispatcher) {
|
|
24
24
|
let wrappedDispatcher = dispatcherCache.get(dispatcher)
|
|
@@ -79,6 +79,7 @@ function wrapDispatcher(dispatcher) {
|
|
|
79
79
|
? origin[Math.floor(Math.random() * origin.length)]
|
|
80
80
|
: origin,
|
|
81
81
|
)),
|
|
82
|
+
maxRedirections: 0, // TODO (fix): Ugly hack to disable undici redirections.
|
|
82
83
|
},
|
|
83
84
|
handler,
|
|
84
85
|
)
|
package/lib/interceptor/dns.js
CHANGED
|
@@ -57,9 +57,9 @@ export default (interceptorOpts) => (dispatch) => (opts, handler) => {
|
|
|
57
57
|
|
|
58
58
|
assert(typeof resolver.lookup === 'function')
|
|
59
59
|
|
|
60
|
-
const { hostname } = new URL(opts.origin)
|
|
60
|
+
const { hostname, host } = new URL(opts.origin)
|
|
61
61
|
|
|
62
|
-
if (net.isIP(hostname)) {
|
|
62
|
+
if (net.isIP(hostname) || opts.headers?.host) {
|
|
63
63
|
return dispatch(opts, handler)
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -72,7 +72,11 @@ export default (interceptorOpts) => (dispatch) => (opts, handler) => {
|
|
|
72
72
|
? val[Math.floor(val.length * Math.random())].address
|
|
73
73
|
: val?.address ?? val
|
|
74
74
|
dispatch(
|
|
75
|
-
{
|
|
75
|
+
{
|
|
76
|
+
...opts,
|
|
77
|
+
origin: url.origin,
|
|
78
|
+
headers: { ...opts.headers, host },
|
|
79
|
+
},
|
|
76
80
|
resolver.clear ? new Handler({ resolver, key: hostname }, { handler }) : handler,
|
|
77
81
|
)
|
|
78
82
|
}
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import tp from 'node:timers/promises'
|
|
2
2
|
import cacheControlParser from 'cache-control-parser'
|
|
3
3
|
import stream from 'node:stream'
|
|
4
|
-
import { util } from '
|
|
4
|
+
import { util } from 'undici'
|
|
5
5
|
|
|
6
6
|
export function parseCacheControl(str) {
|
|
7
7
|
return str ? cacheControlParser.parse(str) : null
|
|
@@ -194,15 +194,6 @@ export function parseOrigin(url) {
|
|
|
194
194
|
return url
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
/**
|
|
198
|
-
* @param {Record<string, string | string[] | null | undefined> | (Buffer | string | (Buffer | string)[])[]} headers
|
|
199
|
-
* @param {Record<string, string | string[]>} [obj]
|
|
200
|
-
* @returns {Record<string, string | string[]>}
|
|
201
|
-
*/
|
|
202
|
-
export function parseHeaders(headers, obj) {
|
|
203
|
-
return util.parseHeaders(headers, obj)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
197
|
export class AbortError extends Error {
|
|
207
198
|
constructor(message) {
|
|
208
199
|
super(message ?? 'The operation was aborted')
|
|
@@ -290,3 +281,89 @@ export class DecoratorHandler {
|
|
|
290
281
|
return this.#handler.onBodySent?.(...args)
|
|
291
282
|
}
|
|
292
283
|
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @param {Record<string, string | string[] | null | undefined> | (Buffer | string | (Buffer | string)[])[]} headers
|
|
287
|
+
* @param {Record<string, string | string[]>} [obj]
|
|
288
|
+
* @returns {Record<string, string | string[]>}
|
|
289
|
+
*/
|
|
290
|
+
export function parseHeaders(headers, obj) {
|
|
291
|
+
if (obj == null) {
|
|
292
|
+
obj = {}
|
|
293
|
+
} else {
|
|
294
|
+
// TODO (fix): assert obj values type?
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (Array.isArray(headers)) {
|
|
298
|
+
for (let i = 0; i < headers.length; i += 2) {
|
|
299
|
+
const key2 = headers[i]
|
|
300
|
+
const val2 = headers[i + 1]
|
|
301
|
+
|
|
302
|
+
// TODO (fix): assert key2 type?
|
|
303
|
+
// TODO (fix): assert val2 type?
|
|
304
|
+
|
|
305
|
+
if (val2 == null) {
|
|
306
|
+
continue
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const key = util.headerNameToString(key2)
|
|
310
|
+
let val = obj[key]
|
|
311
|
+
|
|
312
|
+
if (val) {
|
|
313
|
+
if (!Array.isArray(val)) {
|
|
314
|
+
val = [val]
|
|
315
|
+
obj[key] = val
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (Array.isArray(val2)) {
|
|
319
|
+
val.push(...val2.filter((x) => x != null).map((x) => `${x}`))
|
|
320
|
+
} else {
|
|
321
|
+
val.push(`${val2}`)
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
obj[key] = Array.isArray(val2)
|
|
325
|
+
? val2.filter((x) => x != null).map((x) => `${x}`)
|
|
326
|
+
: `${val2}`
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} else if (typeof headers === 'object' && headers !== null) {
|
|
330
|
+
for (const key2 of Object.keys(headers)) {
|
|
331
|
+
const val2 = headers[key2]
|
|
332
|
+
|
|
333
|
+
// TODO (fix): assert key2 type?
|
|
334
|
+
// TODO (fix): assert val2 type?
|
|
335
|
+
|
|
336
|
+
if (val2 == null) {
|
|
337
|
+
continue
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const key = util.headerNameToString(key2)
|
|
341
|
+
let val = obj[key]
|
|
342
|
+
|
|
343
|
+
if (val) {
|
|
344
|
+
if (!Array.isArray(val)) {
|
|
345
|
+
val = [val]
|
|
346
|
+
obj[key] = val
|
|
347
|
+
}
|
|
348
|
+
if (Array.isArray(val2)) {
|
|
349
|
+
val.push(...val2.filter((x) => x != null).map((x) => `${x}`))
|
|
350
|
+
} else {
|
|
351
|
+
val.push(`${val2}`)
|
|
352
|
+
}
|
|
353
|
+
} else if (val2 != null) {
|
|
354
|
+
obj[key] = Array.isArray(val2)
|
|
355
|
+
? val2.filter((x) => x != null).map((x) => `${x}`)
|
|
356
|
+
: `${val2}`
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
} else if (headers != null) {
|
|
360
|
+
throw new Error('invalid argument: headers')
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// See https://github.com/nodejs/node/pull/46528
|
|
364
|
+
if ('content-length' in obj && 'content-disposition' in obj) {
|
|
365
|
+
obj['content-disposition'] = Buffer.from(obj['content-disposition']).toString('latin1')
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return obj
|
|
369
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/nxt-undici",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -9,28 +9,28 @@
|
|
|
9
9
|
"lib/*"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@nxtedition/undici": "^8.1.0",
|
|
13
12
|
"cache-control-parser": "^2.0.6",
|
|
14
13
|
"cacheable-lookup": "^7.0.0",
|
|
15
14
|
"http-errors": "^2.0.0",
|
|
16
|
-
"lru-cache": "^
|
|
15
|
+
"lru-cache": "^11.0.0",
|
|
16
|
+
"undici": "^6.19.5"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/node": "^
|
|
19
|
+
"@types/node": "^22.0.2",
|
|
20
20
|
"eslint": "^8.0.0",
|
|
21
21
|
"eslint-config-prettier": "^9.1.0",
|
|
22
22
|
"eslint-config-standard": "^17.0.0",
|
|
23
23
|
"eslint-plugin-import": "^2.29.1",
|
|
24
|
-
"eslint-plugin-n": "^17.
|
|
25
|
-
"eslint-plugin-promise": "^
|
|
26
|
-
"husky": "^9.
|
|
24
|
+
"eslint-plugin-n": "^17.10.1",
|
|
25
|
+
"eslint-plugin-promise": "^7.0.0",
|
|
26
|
+
"husky": "^9.1.4",
|
|
27
27
|
"lint-staged": "^15.2.7",
|
|
28
28
|
"pinst": "^3.0.0",
|
|
29
|
-
"prettier": "^3.3.
|
|
30
|
-
"tap": "^
|
|
29
|
+
"prettier": "^3.3.3",
|
|
30
|
+
"tap": "^21.0.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"prepare": "husky
|
|
33
|
+
"prepare": "husky",
|
|
34
34
|
"prepublishOnly": "pinst --disable",
|
|
35
35
|
"postpublish": "pinst --enable",
|
|
36
36
|
"test": "tap test"
|