MCPcopy
hub / github.com/nodejs/undici / schemeFetch

Function schemeFetch

lib/web/fetch/index.js:813–1007  ·  view source on GitHub ↗
(fetchParams)

Source from the content-addressed store, hash-verified

811// https://fetch.spec.whatwg.org/#concept-scheme-fetch
812// given a fetch params fetchParams
813function schemeFetch (fetchParams) {
814 // Note: since the connection is destroyed on redirect, which sets fetchParams to a
815 // cancelled state, we do not want this condition to trigger *unless* there have been
816 // no redirects. See https://github.com/nodejs/undici/issues/1776
817 // 1. If fetchParams is canceled, then return the appropriate network error for fetchParams.
818 if (isCancelled(fetchParams) && fetchParams.request.redirectCount === 0) {
819 return Promise.resolve(makeAppropriateNetworkError(fetchParams))
820 }
821
822 // 2. Let request be fetchParams’s request.
823 const { request } = fetchParams
824
825 const { protocol: scheme } = requestCurrentURL(request)
826
827 // 3. Switch on request’s current URL’s scheme and run the associated steps:
828 switch (scheme) {
829 case 'about:': {
830 // If request’s current URL’s path is the string "blank", then return a new response
831 // whose status message is `OK`, header list is « (`Content-Type`, `text/html;charset=utf-8`) »,
832 // and body is the empty byte sequence as a body.
833
834 // Otherwise, return a network error.
835 return Promise.resolve(makeNetworkError('about scheme is not supported'))
836 }
837 case 'blob:': {
838 if (!resolveObjectURL) {
839 resolveObjectURL = require('node:buffer').resolveObjectURL
840 }
841
842 // 1. Let blobURLEntry be request’s current URL’s blob URL entry.
843 const blobURLEntry = requestCurrentURL(request)
844
845 // https://github.com/web-platform-tests/wpt/blob/7b0ebaccc62b566a1965396e5be7bb2bc06f841f/FileAPI/url/resources/fetch-tests.js#L52-L56
846 // Buffer.resolveObjectURL does not ignore URL queries.
847 if (blobURLEntry.search.length !== 0) {
848 return Promise.resolve(makeNetworkError('NetworkError when attempting to fetch resource.'))
849 }
850
851 const blob = resolveObjectURL(blobURLEntry.toString())
852
853 // 2. If request’s method is not `GET`, blobURLEntry is null, or blobURLEntry’s
854 // object is not a Blob object, then return a network error.
855 if (request.method !== 'GET' || !webidl.is.Blob(blob)) {
856 return Promise.resolve(makeNetworkError('invalid method'))
857 }
858
859 // 3. Let blob be blobURLEntry’s object.
860 // Note: done above
861
862 // 4. Let response be a new response.
863 const response = makeResponse()
864
865 // 5. Let fullLength be blob’s size.
866 const fullLength = blob.size
867
868 // 6. Let serializedFullLength be fullLength, serialized and isomorphic encoded.
869 const serializedFullLength = isomorphicEncode(`${fullLength}`)
870

Callers 1

mainFetchFunction · 0.85

Calls 15

isCancelledFunction · 0.85
requestCurrentURLFunction · 0.85
makeNetworkErrorFunction · 0.85
isomorphicEncodeFunction · 0.85
extractBodyFunction · 0.85
simpleRangeHeaderValueFunction · 0.85
buildContentRangeFunction · 0.85
dataURLProcessorFunction · 0.85
serializeAMimeTypeFunction · 0.85
safelyExtractBodyFunction · 0.85
httpFetchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…