MCPcopy
hub / github.com/nodejs/undici / parseHeaders

Function parseHeaders

lib/core/util.js:420–464  ·  view source on GitHub ↗

* @param {(Buffer | string)[]} headers * @param {Record } [obj] * @returns {Record }

(headers, obj)

Source from the content-addressed store, hash-verified

418 * @returns {Record<string, string | string[]>}
419 */
420function parseHeaders (headers, obj) {
421 if (obj === undefined) obj = {}
422
423 for (let i = 0; i < headers.length; i += 2) {
424 const key = headerNameToString(headers[i])
425 let val = obj[key]
426
427 if (val !== undefined) {
428 if (!Object.hasOwn(obj, key)) {
429 const headersValue = typeof headers[i + 1] === 'string'
430 ? headers[i + 1]
431 : Array.isArray(headers[i + 1])
432 ? headers[i + 1].map(x => x.toString('latin1'))
433 : headers[i + 1].toString('latin1')
434
435 if (key === '__proto__') {
436 Object.defineProperty(obj, key, {
437 value: headersValue,
438 enumerable: true,
439 configurable: true,
440 writable: true
441 })
442 } else {
443 obj[key] = headersValue
444 }
445 } else {
446 if (typeof val === 'string') {
447 val = [val]
448 obj[key] = val
449 }
450 val.push(headers[i + 1].toString('latin1'))
451 }
452 } else {
453 const headersValue = typeof headers[i + 1] === 'string'
454 ? headers[i + 1]
455 : Array.isArray(headers[i + 1])
456 ? headers[i + 1].map(x => x.toString('latin1'))
457 : headers[i + 1].toString('latin1')
458
459 obj[key] = headersValue
460 }
461 }
462
463 return obj
464}
465
466/**
467 * @param {Buffer[] | string[] | Record<string, string | string[]> | null | undefined} headers

Callers 5

parse-headers.mjsFile · 0.90
onResponseStartMethod · 0.85
onRequestUpgradeMethod · 0.85
onResponseEndMethod · 0.85
handleReplyFunction · 0.85

Calls 4

headerNameToStringFunction · 0.85
mapMethod · 0.80
toStringMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…