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

Function parseRawHeaders

lib/core/util.js:470–512  ·  view source on GitHub ↗

* @param {Buffer[] | string[] | Record | null | undefined} headers * @returns {string[]}

(headers)

Source from the content-addressed store, hash-verified

468 * @returns {string[]}
469 */
470function parseRawHeaders (headers) {
471 if (headers == null) {
472 return []
473 }
474
475 if (!Array.isArray(headers)) {
476 const rawHeaders = []
477
478 for (const [name, value] of Object.entries(headers)) {
479 if (Array.isArray(value)) {
480 for (const entry of value) {
481 rawHeaders.push(name, `${entry}`)
482 }
483 } else {
484 rawHeaders.push(name, `${value}`)
485 }
486 }
487
488 return rawHeaders
489 }
490
491 const headersLength = headers.length
492 /**
493 * @type {string[]}
494 */
495 const ret = new Array(headersLength)
496
497 let key
498 let val
499
500 for (let n = 0; n < headersLength; n += 2) {
501 key = headers[n]
502 val = headers[n + 1]
503
504 typeof key !== 'string' && (key = key.toString())
505 typeof val !== 'string' && (val = val.toString('latin1'))
506
507 ret[n] = key
508 ret[n + 1] = val
509 }
510
511 return ret
512}
513
514/**
515 * @param {Record<string, string | string[]>} headers

Callers 1

Calls 3

entriesMethod · 0.45
pushMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…