MCPcopy Create free account
hub / github.com/nodejs/node / fetchFinale

Function fetchFinale

deps/undici/src/lib/web/fetch/index.js:1023–1146  ·  view source on GitHub ↗
(fetchParams, response)

Source from the content-addressed store, hash-verified

1021
1022// https://fetch.spec.whatwg.org/#fetch-finale
1023function fetchFinale (fetchParams, response) {
1024 // 1. Let timingInfo be fetchParams’s timing info.
1025 let timingInfo = fetchParams.timingInfo
1026
1027 // 2. If response is not a network error and fetchParams’s request’s client is a secure context,
1028 // then set timingInfo’s server-timing headers to the result of getting, decoding, and splitting
1029 // `Server-Timing` from response’s internal response’s header list.
1030 // TODO
1031
1032 // 3. Let processResponseEndOfBody be the following steps:
1033 const processResponseEndOfBody = () => {
1034 // 1. Let unsafeEndTime be the unsafe shared current time.
1035 const unsafeEndTime = Date.now() // ?
1036
1037 // 2. If fetchParams’s request’s destination is "document", then set fetchParams’s controller’s
1038 // full timing info to fetchParams’s timing info.
1039 if (fetchParams.request.destination === 'document') {
1040 fetchParams.controller.fullTimingInfo = timingInfo
1041 }
1042
1043 // 3. Set fetchParams’s controller’s report timing steps to the following steps given a global object global:
1044 fetchParams.controller.reportTimingSteps = () => {
1045 // 1. If fetchParams’s request’s URL’s scheme is not an HTTP(S) scheme, then return.
1046 if (!urlIsHttpHttpsScheme(fetchParams.request.url)) {
1047 return
1048 }
1049
1050 // 2. Set timingInfo’s end time to the relative high resolution time given unsafeEndTime and global.
1051 timingInfo.endTime = unsafeEndTime
1052
1053 // 3. Let cacheState be response’s cache state.
1054 let cacheState = response.cacheState
1055
1056 // 4. Let bodyInfo be response’s body info.
1057 const bodyInfo = response.bodyInfo
1058
1059 // 5. If response’s timing allow passed flag is not set, then set timingInfo to the result of creating an
1060 // opaque timing info for timingInfo and set cacheState to the empty string.
1061 if (!response.timingAllowPassed) {
1062 timingInfo = createOpaqueTimingInfo(timingInfo)
1063
1064 cacheState = ''
1065 }
1066
1067 // 6. Let responseStatus be 0.
1068 let responseStatus = 0
1069
1070 // 7. If fetchParams’s request’s mode is not "navigate" or response’s has-cross-origin-redirects is false:
1071 if (fetchParams.request.mode !== 'navigate' || !response.hasCrossOriginRedirects) {
1072 // 1. Set responseStatus to response’s status.
1073 responseStatus = response.status
1074
1075 // 2. Let mimeType be the result of extracting a MIME type from response’s header list.
1076 const mimeType = extractMimeType(response.headersList)
1077
1078 // 3. If mimeType is not failure, then set bodyInfo’s content type to the result of minimizing a supported MIME type given mimeType.
1079 if (mimeType !== 'failure') {
1080 bodyInfo.contentType = minimizeSupportedMimeType(mimeType)

Callers 3

processBodyErrorFunction · 0.70
processBodyFunction · 0.70
mainFetchFunction · 0.70

Calls 4

queueMicrotaskFunction · 0.85
processResponseEndOfBodyFunction · 0.85
processResponseMethod · 0.80
finishedFunction · 0.50

Tested by

no test coverage detected