MCPcopy Index your code
hub / github.com/nodejs/node / convertHeaderObject

Function convertHeaderObject

lib/internal/inspector/network_http.js:40–69  ·  view source on GitHub ↗
(headers = kEmptyObject)

Source from the content-addressed store, hash-verified

38
39// Convert a Headers object (Map<string, number | string | string[]>) to a plain object (Map<string, string>)
40const convertHeaderObject = (headers = kEmptyObject) => {
41 // The 'host' header that contains the host and port of the URL.
42 let host;
43 let charset;
44 let mimeType;
45 const dict = {};
46 for (const { 0: key, 1: value } of ObjectEntries(headers)) {
47 const lowerCasedKey = key.toLowerCase();
48 if (lowerCasedKey === 'host') {
49 host = value;
50 }
51 if (lowerCasedKey === 'content-type') {
52 const result = sniffMimeType(value);
53 charset = result.charset;
54 mimeType = result.mimeType;
55 }
56 if (typeof value === 'string') {
57 dict[key] = value;
58 } else if (ArrayIsArray(value)) {
59 if (lowerCasedKey === 'cookie') dict[key] = value.join('; ');
60 // ChromeDevTools frontend treats 'set-cookie' as a special case
61 // https://github.com/ChromeDevTools/devtools-frontend/blob/4275917f84266ef40613db3c1784a25f902ea74e/front_end/core/sdk/NetworkRequest.ts#L1368
62 else if (lowerCasedKey === 'set-cookie') dict[key] = value.join('\n');
63 else dict[key] = value.join(', ');
64 } else {
65 dict[key] = String(value);
66 }
67 }
68 return [dict, host, charset, mimeType];
69};
70
71/**
72 * When a client request is created, emit Network.requestWillBeSent event.

Callers 2

onClientRequestCreatedFunction · 0.70
onClientResponseFinishFunction · 0.70

Calls 3

sniffMimeTypeFunction · 0.85
StringClass · 0.85
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…