MCPcopy
hub / github.com/ampproject/amphtml / parseHeaders

Function parseHeaders

src/document-fetcher.js:114–128  ·  view source on GitHub ↗

* Parses XHR's response headers into JSONObject. * @param {string} rawHeaders * @return {!JsonObject}

(rawHeaders)

Source from the content-addressed store, hash-verified

112 * @return {!JsonObject}
113 */
114function parseHeaders(rawHeaders) {
115 const headers = {};
116 // Replace instances of \r\n and \n followed by at least one space or
117 // horizontal tab with a space.
118 const preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
119 preProcessedHeaders.split(/\r?\n/).forEach(function (line) {
120 const parts = line.split(':');
121 const key = parts.shift().trim();
122 if (key) {
123 const value = parts.join(':').trim();
124 headers[key] = value;
125 }
126 });
127 return headers;
128}

Callers 1

xhrRequestFunction · 0.85

Calls 2

replaceMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected