(body, responseHeaders)
| 210 | } |
| 211 | |
| 212 | async function prepareResponseHeaders(body, responseHeaders) { |
| 213 | const defaultHeaders = [...interceptor.scope._defaultReplyHeaders] |
| 214 | const rawHeaders = [] |
| 215 | |
| 216 | // Include a JSON content type when JSON.stringify is called on the body. |
| 217 | // This is a convenience added by Nock that has no analog in Node. It's added to the |
| 218 | // defaults, so it will be ignored if the caller explicitly provided the header already. |
| 219 | const isJSON = |
| 220 | body !== undefined && |
| 221 | typeof body !== 'string' && |
| 222 | !Buffer.isBuffer(body) && |
| 223 | !common.isStream(body) |
| 224 | |
| 225 | if (isJSON) { |
| 226 | defaultHeaders.push('Content-Type', 'application/json') |
| 227 | } |
| 228 | common.forEachHeader( |
| 229 | [...interceptor.rawHeaders, ...responseHeaders], |
| 230 | (value, fieldName) => { |
| 231 | rawHeaders.push([fieldName, value]) |
| 232 | }, |
| 233 | ) |
| 234 | |
| 235 | rawHeaders.push( |
| 236 | ...selectDefaultHeaders( |
| 237 | [...interceptor.rawHeaders, ...responseHeaders], |
| 238 | defaultHeaders, |
| 239 | ), |
| 240 | ) |
| 241 | |
| 242 | for (let i = 0; i < rawHeaders.length; i++) { |
| 243 | const [, value] = rawHeaders[i] |
| 244 | |
| 245 | // Evaluate functional headers. |
| 246 | if (typeof value === 'function') { |
| 247 | rawHeaders[i][1] = await value(decompressedRequest) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | return new Headers(rawHeaders) |
| 252 | } |
| 253 | |
| 254 | async function continueWithResponseBody( |
| 255 | rawBody, |
no test coverage detected
searching dependent graphs…