MCPcopy
hub / github.com/axios/axios / request

Function request

tests/smoke/cjs/tests/files.smoke.test.cjs:8–49  ·  view source on GitHub ↗
(options, onResponse)

Source from the content-addressed store, hash-verified

6const createCaptureTransport = (buildResponse) => {
7 return {
8 request(options, onResponse) {
9 const chunks = [];
10
11 const req = new Writable({
12 write(chunk, _encoding, callback) {
13 chunks.push(Buffer.from(chunk));
14 callback();
15 },
16 });
17
18 req.destroyed = false;
19 req.setTimeout = () => {};
20 req.close = () => {
21 req.destroyed = true;
22 };
23
24 const originalDestroy = req.destroy.bind(req);
25 req.destroy = (...args) => {
26 req.destroyed = true;
27 return originalDestroy(...args);
28 };
29
30 const originalEnd = req.end.bind(req);
31 req.end = (...args) => {
32 originalEnd(...args);
33
34 const body = Buffer.concat(chunks);
35 const response = buildResponse ? buildResponse(body, options) : {};
36
37 const res = new PassThrough();
38 res.statusCode = response.statusCode !== undefined ? response.statusCode : 200;
39 res.statusMessage = response.statusMessage || 'OK';
40 res.headers = response.headers || { 'content-type': 'application/json' };
41 res.req = req;
42
43 onResponse(res);
44 res.end(response.body || JSON.stringify({ size: body.length }));
45 };
46
47 req.on('error', () => {});
48 return req;
49 },
50 };
51};
52

Callers

nothing calls this directly

Calls 2

concatMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected