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

Method constructor

src/polyfills/fetch.js:245–282  ·  view source on GitHub ↗

* Returns instance of Response. * @param {?ResponseBodyInit=} body * @param {!ResponseInit=} init

(body, init = {})

Source from the content-addressed store, hash-verified

243 * @param {!ResponseInit=} init
244 */
245 constructor(body, init = {}) {
246 const lowercasedHeaders = map();
247 const data = {
248 status: 200,
249 statusText: 'OK',
250 responseText: body ? String(body) : '',
251 getResponseHeader(name) {
252 const headerName = String(name).toLowerCase();
253 return hasOwn(lowercasedHeaders, headerName)
254 ? lowercasedHeaders[headerName]
255 : null;
256 },
257 ...init,
258 };
259
260 data.status = init.status === undefined ? 200 : parseInt(init.status, 10);
261
262 if (isArray(init.headers)) {
263 /** @type {!Array} */ (init.headers).forEach((entry) => {
264 const headerName = entry[0];
265 const headerValue = entry[1];
266 lowercasedHeaders[String(headerName).toLowerCase()] =
267 String(headerValue);
268 });
269 } else if (isObject(init.headers)) {
270 for (const key in init.headers) {
271 lowercasedHeaders[String(key).toLowerCase()] = String(
272 init.headers[key]
273 );
274 }
275 }
276
277 if (init.statusText) {
278 data.statusText = String(init.statusText);
279 }
280
281 super(/** @type {XMLHttpRequestDef} */ (data));
282 }
283}
284
285/**

Callers

nothing calls this directly

Calls 5

mapFunction · 0.90
isObjectFunction · 0.90
isArrayFunction · 0.85
StringFunction · 0.50
forEachMethod · 0.45

Tested by

no test coverage detected