@nxtedition/nxt-undici 2.0.52 → 2.0.54
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 +1 -1
- package/lib/interceptor/cache.js +1 -1
- package/lib/interceptor/request-body-factory.js +1 -0
- package/lib/utils.js +76 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -128,7 +128,7 @@ export async function request(url, opts) {
|
|
|
128
128
|
idempotent: opts.idempotent,
|
|
129
129
|
retry: opts.retry ?? 8,
|
|
130
130
|
proxy: opts.proxy ?? false,
|
|
131
|
-
cache: opts.cache ??
|
|
131
|
+
cache: opts.cache ?? false,
|
|
132
132
|
upgrade: opts.upgrade ?? false,
|
|
133
133
|
follow: opts.follow ?? 8,
|
|
134
134
|
error: opts.error ?? true,
|
package/lib/interceptor/cache.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -201,14 +201,85 @@ export function parseOrigin(url) {
|
|
|
201
201
|
return url
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
/**
|
|
205
|
+
* @param {Record<string, string | string[] | null | undefined> | (Buffer | string | (Buffer | string)[])[]} headers
|
|
206
|
+
* @param {Record<string, string | string[]>} [obj]
|
|
207
|
+
* @returns {Record<string, string | string[]>}
|
|
208
|
+
*/
|
|
209
|
+
export function parseHeaders(headers, obj) {
|
|
210
|
+
if (obj == null) {
|
|
211
|
+
obj = {}
|
|
212
|
+
} else {
|
|
213
|
+
// TODO (fix): assert obj values type?
|
|
214
|
+
}
|
|
215
|
+
|
|
205
216
|
if (Array.isArray(headers)) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
217
|
+
for (let i = 0; i < headers.length; i += 2) {
|
|
218
|
+
const key2 = headers[i]
|
|
219
|
+
const val2 = headers[i + 1]
|
|
220
|
+
|
|
221
|
+
// TODO (fix): assert key2 type?
|
|
222
|
+
// TODO (fix): assert val2 type?
|
|
223
|
+
|
|
224
|
+
if (!val2) {
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const key = headerNameToString(key2)
|
|
229
|
+
let val = obj[key]
|
|
230
|
+
|
|
231
|
+
if (val) {
|
|
232
|
+
if (typeof val === 'string') {
|
|
233
|
+
val = [val]
|
|
234
|
+
obj[key] = val
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (Array.isArray(val2)) {
|
|
238
|
+
val.push(...val2.map((x) => x.toString()))
|
|
239
|
+
} else {
|
|
240
|
+
val.push(val2.toString())
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
obj[key] = Array.isArray(val2) ? val2.map((x) => x.toString()) : val2.toString()
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
} else if (typeof headers === 'object' && headers !== null) {
|
|
247
|
+
for (const key2 of Object.keys(headers)) {
|
|
248
|
+
const val2 = headers[key2]
|
|
249
|
+
|
|
250
|
+
// TODO (fix): assert key2 type?
|
|
251
|
+
// TODO (fix): assert val2 type?
|
|
252
|
+
|
|
253
|
+
if (!val2) {
|
|
254
|
+
continue
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const key = headerNameToString(key2)
|
|
258
|
+
let val = obj[key]
|
|
259
|
+
|
|
260
|
+
if (val) {
|
|
261
|
+
if (typeof val === 'string') {
|
|
262
|
+
val = [val]
|
|
263
|
+
obj[key] = val
|
|
264
|
+
}
|
|
265
|
+
if (Array.isArray(val2)) {
|
|
266
|
+
val.push(...val2.map((x) => x.toString()))
|
|
267
|
+
} else {
|
|
268
|
+
val.push(val2.toString())
|
|
269
|
+
}
|
|
270
|
+
} else if (val2 != null) {
|
|
271
|
+
obj[key] = Array.isArray(val2) ? val2.map((x) => x.toString()) : val2.toString()
|
|
272
|
+
}
|
|
210
273
|
}
|
|
274
|
+
} else if (headers != null) {
|
|
275
|
+
throw new Error('invalid argument: headers')
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// See https://github.com/nodejs/node/pull/46528
|
|
279
|
+
if ('content-length' in obj && 'content-disposition' in obj) {
|
|
280
|
+
obj['content-disposition'] = Buffer.from(obj['content-disposition']).toString('latin1')
|
|
211
281
|
}
|
|
282
|
+
|
|
212
283
|
return obj
|
|
213
284
|
}
|
|
214
285
|
|