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 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(encoding)
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(encoding))
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
- const encoding = key.length === 19 && key.toLowerCase() === 'content-disposition'
252
- ? 'latin1'
253
- : 'utf8'
254
-
255
- const val = headers[n + 1].toString(encoding)
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
- ret.push(key, val)
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
 
@@ -95,6 +95,7 @@ class HeadersList {
95
95
  clear () {
96
96
  this[kHeadersMap].clear()
97
97
  this[kHeadersSortedMap] = null
98
+ this.cookies = null
98
99
  }
99
100
 
100
101
  // https://fetch.spec.whatwg.org/#concept-header-list-append
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "5.21.1",
3
+ "version": "5.21.2",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {