MCPcopy
hub / github.com/axios/axios / getBodyLength

Function getBodyLength

lib/adapters/fetch.js:159–187  ·  view source on GitHub ↗
(body)

Source from the content-addressed store, hash-verified

157 })();
158
159 const getBodyLength = async (body) => {
160 if (body == null) {
161 return 0;
162 }
163
164 if (utils.isBlob(body)) {
165 return body.size;
166 }
167
168 if (utils.isSpecCompliantForm(body)) {
169 const _request = new Request(platform.origin, {
170 method: 'POST',
171 body,
172 });
173 return (await _request.arrayBuffer()).byteLength;
174 }
175
176 if (utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
177 return body.byteLength;
178 }
179
180 if (utils.isURLSearchParams(body)) {
181 body = body + '';
182 }
183
184 if (utils.isString(body)) {
185 return (await encodeText(body)).byteLength;
186 }
187 };
188
189 const resolveBodyLength = async (headers, body) => {
190 const length = utils.toFiniteNumber(headers.getContentLength());

Callers 2

resolveBodyLengthFunction · 0.85
factoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected