MCPcopy
hub / github.com/axios/axios / factory

Function factory

lib/adapters/fetch.js:68–614  ·  view source on GitHub ↗
(env)

Source from the content-addressed store, hash-verified

66};
67
68const factory = (env) => {
69 const globalObject =
70 utils.global !== undefined && utils.global !== null
71 ? utils.global
72 : globalThis;
73 const { ReadableStream, TextEncoder } = globalObject;
74
75 env = utils.merge.call(
76 {
77 skipUndefined: true,
78 },
79 {
80 Request: globalObject.Request,
81 Response: globalObject.Response,
82 },
83 env
84 );
85
86 const { fetch: envFetch, Request, Response } = env;
87 const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
88 const isRequestSupported = isFunction(Request);
89 const isResponseSupported = isFunction(Response);
90
91 if (!isFetchSupported) {
92 return false;
93 }
94
95 const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream);
96
97 const encodeText =
98 isFetchSupported &&
99 (typeof TextEncoder === 'function'
100 ? (
101 (encoder) => (str) =>
102 encoder.encode(str)
103 )(new TextEncoder())
104 : async (str) => new Uint8Array(await new Request(str).arrayBuffer()));
105
106 const supportsRequestStream =
107 isRequestSupported &&
108 isReadableStreamSupported &&
109 test(() => {
110 let duplexAccessed = false;
111
112 const request = new Request(platform.origin, {
113 body: new ReadableStream(),
114 method: 'POST',
115 get duplex() {
116 duplexAccessed = true;
117 return 'half';
118 },
119 });
120
121 const hasContentType = request.headers.has('Content-Type');
122
123 if (request.body != null) {
124 request.body.cancel();
125 }

Callers 1

getFetchFunction · 0.85

Calls 15

progressEventDecoratorFunction · 0.90
progressEventReducerFunction · 0.90
asyncDecoratorFunction · 0.90
toByteStringHeaderObjectFunction · 0.90
trackStreamFunction · 0.90
testFunction · 0.85
resolveConfigFunction · 0.85
composeSignalsFunction · 0.85
maybeWithAuthCredentialsFunction · 0.85
getBodyLengthFunction · 0.85
maxBodyLengthErrorFunction · 0.85

Tested by

no test coverage detected