undici 5.21.1 → 5.21.2
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/core/util.js +25 -12
- package/lib/fetch/headers.js +1 -0
- package/package.json +1 -1
package/lib/core/util.js
CHANGED
|
@@ -222,40 +222,53 @@ function parseHeaders (headers, obj = {}) {
|
|
|
222
222
|
const key = headers[i].toString().toLowerCase()
|
|
223
223
|
let val = obj[key]
|
|
224
224
|
|
|
225
|
-
const encoding = key.length === 19 && key === 'content-disposition'
|
|
226
|
-
? 'latin1'
|
|
227
|
-
: 'utf8'
|
|
228
|
-
|
|
229
225
|
if (!val) {
|
|
230
226
|
if (Array.isArray(headers[i + 1])) {
|
|
231
227
|
obj[key] = headers[i + 1]
|
|
232
228
|
} else {
|
|
233
|
-
obj[key] = headers[i + 1].toString(
|
|
229
|
+
obj[key] = headers[i + 1].toString('utf8')
|
|
234
230
|
}
|
|
235
231
|
} else {
|
|
236
232
|
if (!Array.isArray(val)) {
|
|
237
233
|
val = [val]
|
|
238
234
|
obj[key] = val
|
|
239
235
|
}
|
|
240
|
-
val.push(headers[i + 1].toString(
|
|
236
|
+
val.push(headers[i + 1].toString('utf8'))
|
|
241
237
|
}
|
|
242
238
|
}
|
|
239
|
+
|
|
240
|
+
// See https://github.com/nodejs/node/pull/46528
|
|
241
|
+
if ('content-length' in obj && 'content-disposition' in obj) {
|
|
242
|
+
obj['content-disposition'] = Buffer.from(obj['content-disposition']).toString('latin1')
|
|
243
|
+
}
|
|
244
|
+
|
|
243
245
|
return obj
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
function parseRawHeaders (headers) {
|
|
247
249
|
const ret = []
|
|
250
|
+
let hasContentLength = false
|
|
251
|
+
let contentDispositionIdx = -1
|
|
252
|
+
|
|
248
253
|
for (let n = 0; n < headers.length; n += 2) {
|
|
249
254
|
const key = headers[n + 0].toString()
|
|
255
|
+
const val = headers[n + 1].toString('utf8')
|
|
250
256
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
257
|
+
if (key.length === 14 && (key === 'content-length' || key.toLowerCase() === 'content-length')) {
|
|
258
|
+
ret.push(key, val)
|
|
259
|
+
hasContentLength = true
|
|
260
|
+
} else if (key.length === 19 && (key === 'content-disposition' || key.toLowerCase() === 'content-disposition')) {
|
|
261
|
+
contentDispositionIdx = ret.push(key, val) - 1
|
|
262
|
+
} else {
|
|
263
|
+
ret.push(key, val)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
256
266
|
|
|
257
|
-
|
|
267
|
+
// See https://github.com/nodejs/node/pull/46528
|
|
268
|
+
if (hasContentLength && contentDispositionIdx !== -1) {
|
|
269
|
+
ret[contentDispositionIdx] = Buffer.from(ret[contentDispositionIdx]).toString('latin1')
|
|
258
270
|
}
|
|
271
|
+
|
|
259
272
|
return ret
|
|
260
273
|
}
|
|
261
274
|
|
package/lib/fetch/headers.js
CHANGED