MCPcopy Create free account
hub / github.com/nodejs/node / normalizeHeaders

Function normalizeHeaders

deps/undici/src/lib/util/cache.js:37–65  ·  view source on GitHub ↗

* @param {Record } * @returns {Record }

(opts)

Source from the content-addressed store, hash-verified

35 * @returns {Record<string, string[] | string>}
36 */
37function normalizeHeaders (opts) {
38 let headers
39 if (opts.headers == null) {
40 headers = {}
41 } else if (typeof opts.headers === 'object') {
42 headers = {}
43
44 if (hasSafeIterator(opts.headers)) {
45 for (const x of opts.headers) {
46 if (!Array.isArray(x)) {
47 throw new Error('opts.headers is not a valid header map')
48 }
49 const [key, val] = x
50 if (typeof key !== 'string' || typeof val !== 'string') {
51 throw new Error('opts.headers is not a valid header map')
52 }
53 headers[key.toLowerCase()] = val
54 }
55 } else {
56 for (const key of Object.keys(opts.headers)) {
57 headers[key.toLowerCase()] = opts.headers[key]
58 }
59 }
60 } else {
61 throw new Error('opts.headers is not an object')
62 }
63
64 return headers
65}
66
67/**
68 * @param {any} key

Callers

nothing calls this directly

Calls 2

keysMethod · 0.65
hasSafeIteratorFunction · 0.50

Tested by

no test coverage detected