({ body })
| 2182 | return response |
| 2183 | |
| 2184 | function dispatch ({ body }) { |
| 2185 | const url = requestCurrentURL(request) |
| 2186 | /** @type {import('../../..').Agent} */ |
| 2187 | const agent = fetchParams.controller.dispatcher |
| 2188 | |
| 2189 | const path = url.pathname + url.search |
| 2190 | const hasTrailingQuestionMark = url.search.length === 0 && url.href[url.href.length - url.hash.length - 1] === '?' |
| 2191 | |
| 2192 | return dispatchWithProtocolPreference(body) |
| 2193 | |
| 2194 | function dispatchWithProtocolPreference (body, allowH2) { |
| 2195 | return new Promise((resolve, reject) => agent.dispatch( |
| 2196 | { |
| 2197 | path: hasTrailingQuestionMark ? `${path}?` : path, |
| 2198 | origin: url.origin, |
| 2199 | method: request.method, |
| 2200 | body: agent.isMockActive ? request.body && (request.body.source || request.body.stream) : body, |
| 2201 | // Preserve the serialized fetch body for MockAgent net-connect fallthroughs. |
| 2202 | __mockAgentBodyForDispatch: body, |
| 2203 | headers: request.headersList.entries, |
| 2204 | maxRedirections: 0, |
| 2205 | upgrade: request.mode === 'websocket' ? 'websocket' : undefined, |
| 2206 | ...(allowH2 === false ? { allowH2 } : null) |
| 2207 | }, |
| 2208 | { |
| 2209 | body: null, |
| 2210 | abort: null, |
| 2211 | |
| 2212 | onRequestStart (controller) { |
| 2213 | // TODO (fix): Do we need connection here? |
| 2214 | const { connection } = fetchParams.controller |
| 2215 | |
| 2216 | // Set timingInfo’s final connection timing info to the result of calling clamp and coarsen |
| 2217 | // connection timing info with connection’s timing info, timingInfo’s post-redirect start |
| 2218 | // time, and fetchParams’s cross-origin isolated capability. |
| 2219 | // TODO: implement connection timing |
| 2220 | timingInfo.finalConnectionTimingInfo = clampAndCoarsenConnectionTimingInfo(undefined, timingInfo.postRedirectStartTime, fetchParams.crossOriginIsolatedCapability) |
| 2221 | |
| 2222 | const abort = (reason) => controller.abort(reason) |
| 2223 | |
| 2224 | if (connection.destroyed) { |
| 2225 | abort(new DOMException('The operation was aborted.', 'AbortError')) |
| 2226 | } else { |
| 2227 | fetchParams.controller.on('terminated', abort) |
| 2228 | this.abort = connection.abort = abort |
| 2229 | } |
| 2230 | |
| 2231 | // Set timingInfo’s final network-request start time to the coarsened shared current time given |
| 2232 | // fetchParams’s cross-origin isolated capability. |
| 2233 | timingInfo.finalNetworkRequestStartTime = coarsenedSharedCurrentTime(fetchParams.crossOriginIsolatedCapability) |
| 2234 | }, |
| 2235 | |
| 2236 | onResponseStarted () { |
| 2237 | // Set timingInfo’s final network-response start time to the coarsened shared current |
| 2238 | // time given fetchParams’s cross-origin isolated capability, immediately after the |
| 2239 | // user agent’s HTTP parser receives the first byte of the response (e.g., frame header |
| 2240 | // bytes for HTTP/2 or response status line for HTTP/1.x). |
| 2241 | timingInfo.finalNetworkResponseStartTime = coarsenedSharedCurrentTime(fetchParams.crossOriginIsolatedCapability) |
no test coverage detected