@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 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 ?? true,
131
+ cache: opts.cache ?? false,
132
132
  upgrade: opts.upgrade ?? false,
133
133
  follow: opts.follow ?? 8,
134
134
  error: opts.error ?? true,
@@ -92,7 +92,7 @@ class CacheStore {
92
92
  this.maxEntrySize = maxEntrySize
93
93
  this.cache = new LRUCache({
94
94
  maxSize,
95
- sizeCalculation: (value) => value.body.byteLength,
95
+ sizeCalculation: (value) => value.size,
96
96
  })
97
97
  }
98
98
 
@@ -17,6 +17,7 @@ export default (dispatch) => (opts, handler) => {
17
17
  dispatch({ ...opts, body }, handler)
18
18
  },
19
19
  (err) => {
20
+ handler.onConnect(() => {})
20
21
  handler.onError(err)
21
22
  },
22
23
  )
package/lib/utils.js CHANGED
@@ -201,14 +201,85 @@ export function parseOrigin(url) {
201
201
  return url
202
202
  }
203
203
 
204
- export function parseHeaders(headers, obj = {}) {
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
- return util.parseHeaders(headers, obj)
207
- } else if (headers != null) {
208
- for (const [key, val] of Object.entries(headers)) {
209
- obj[headerNameToString(key)] = val
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "2.0.52",
3
+ "version": "2.0.54",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",