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

Function convertHeaderObject

lib/internal/inspector/network_http2.js:38–83  ·  view source on GitHub ↗
(headers = kEmptyObject)

Source from the content-addressed store, hash-verified

36
37// Convert a Headers object (Map<string, number | string | string[]>) to a plain object (Map<string, string>)
38function convertHeaderObject(headers = kEmptyObject) {
39 let scheme;
40 let authority;
41 let path;
42 let method;
43 let statusCode;
44 let charset;
45 let mimeType;
46 const dict = {};
47
48 for (const { 0: key, 1: value } of ObjectEntries(headers)) {
49 const lowerCasedKey = key.toLowerCase();
50
51 if (lowerCasedKey === HTTP2_HEADER_SCHEME) {
52 scheme = value;
53 } else if (lowerCasedKey === HTTP2_HEADER_AUTHORITY) {
54 authority = value;
55 } else if (lowerCasedKey === HTTP2_HEADER_PATH) {
56 path = value;
57 } else if (lowerCasedKey === HTTP2_HEADER_METHOD) {
58 method = value;
59 } else if (lowerCasedKey === HTTP2_HEADER_STATUS) {
60 statusCode = value;
61 } else if (lowerCasedKey === HTTP2_HEADER_CONTENT_TYPE) {
62 const result = sniffMimeType(value);
63 charset = result.charset;
64 mimeType = result.mimeType;
65 }
66
67 if (typeof value === 'string') {
68 dict[key] = value;
69 } else if (ArrayIsArray(value)) {
70 if (lowerCasedKey === HTTP2_HEADER_COOKIE) dict[key] = value.join('; ');
71 // ChromeDevTools frontend treats 'set-cookie' as a special case
72 // https://github.com/ChromeDevTools/devtools-frontend/blob/4275917f84266ef40613db3c1784a25f902ea74e/front_end/core/sdk/NetworkRequest.ts#L1368
73 else if (lowerCasedKey === HTTP2_HEADER_SET_COOKIE) dict[key] = value.join('\n');
74 else dict[key] = value.join(', ');
75 } else {
76 dict[key] = String(value);
77 }
78 }
79
80 const url = `${scheme}://${authority}${path}`;
81
82 return [dict, url, method, statusCode, charset, mimeType];
83}
84
85/**
86 * When a client stream is created, emit Network.requestWillBeSent event.

Callers 2

onClientStreamCreatedFunction · 0.70
onClientStreamFinishFunction · 0.70

Calls 3

sniffMimeTypeFunction · 0.85
StringClass · 0.85
joinMethod · 0.45

Tested by

no test coverage detected