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

Function request

tests/smoke/esm/tests/formData.smoke.test.js: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.write = req.write.bind(req);
21 req.close = () => {
22 req.destroyed = true;
23 };
24
25 const originalDestroy = req.destroy.bind(req);
26 req.destroy = (...args) => {
27 req.destroyed = true;
28 return originalDestroy(...args);
29 };
30
31 const originalEnd = req.end.bind(req);
32 req.end = (...args) => {
33 originalEnd(...args);
34
35 const body = Buffer.concat(chunks);
36 const response = buildResponse ? buildResponse(body, options) : {};
37
38 const res = new PassThrough();
39 res.statusCode = response.statusCode !== undefined ? response.statusCode : 200;
40 res.statusMessage = response.statusMessage || 'OK';
41 res.headers = response.headers || { 'content-type': 'application/json' };
42 res.req = req;
43
44 onResponse(res);
45 res.end(response.body || JSON.stringify({ ok: true }));
46 };
47
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