(response, responseType)
| 116 | * @private |
| 117 | */ |
| 118 | export function fromStructuredCloneable(response, responseType) { |
| 119 | userAssert(isObject(response), 'Object expected: %s', response); |
| 120 | |
| 121 | const isDocumentType = responseType == 'document'; |
| 122 | if (!isDocumentType) { |
| 123 | // Use native `Response` type if available for performance. If response |
| 124 | // type is `document`, we must fall back to `FetchResponse` polyfill |
| 125 | // because callers would then rely on the `responseXML` property being |
| 126 | // present, which is not supported by the Response type. |
| 127 | return new Response(response['body'], response['init']); |
| 128 | } |
| 129 | |
| 130 | const lowercasedHeaders = map(); |
| 131 | const data = { |
| 132 | status: 200, |
| 133 | statusText: 'OK', |
| 134 | /** |
| 135 | * @param {string} name |
| 136 | * @return {string} |
| 137 | */ |
| 138 | getResponseHeader(name) { |
| 139 | return lowercasedHeaders[String(name).toLowerCase()] || null; |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | if (response['init']) { |
| 144 | const init = response['init']; |
| 145 | if (isArray(init.headers)) { |
| 146 | /** @type {!Array} */ (init.headers).forEach((entry) => { |
| 147 | const headerName = entry[0]; |
| 148 | const headerValue = entry[1]; |
| 149 | lowercasedHeaders[String(headerName).toLowerCase()] = |
| 150 | String(headerValue); |
| 151 | }); |
| 152 | } |
| 153 | if (init.status) { |
| 154 | data.status = parseInt(init.status, 10); |
| 155 | } |
| 156 | if (init.statusText) { |
| 157 | data.statusText = String(init.statusText); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return new Response(response['body'] ? String(response['body']) : '', data); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Intercepts the XHR and proxies it through the viewer if necessary. |
no test coverage detected