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

Function request

tests/smoke/esm/tests/urlencode.smoke.test.js:11–49  ·  view source on GitHub ↗
(options, onResponse)

Source from the content-addressed store, hash-verified

9
10 const transport = {
11 request(options, onResponse) {
12 capturedOptions = options;
13 const chunks = [];
14
15 const req = new EventEmitter();
16 req.destroyed = false;
17 req.setTimeout = () => {};
18 req.destroy = () => {
19 req.destroyed = true;
20 };
21 req.close = req.destroy;
22 req.write = (chunk) => {
23 chunks.push(Buffer.from(chunk));
24 return true;
25 };
26 req.end = (chunk) => {
27 if (chunk) {
28 chunks.push(Buffer.from(chunk));
29 }
30
31 const res = new PassThrough();
32 res.statusCode = 200;
33 res.statusMessage = 'OK';
34 res.headers = { 'content-type': 'application/json' };
35 res.req = req;
36 onResponse(res);
37 res.end(
38 JSON.stringify({
39 path: options.path,
40 body: Buffer.concat(chunks).toString('utf8'),
41 contentType:
42 options.headers &&
43 (options.headers['Content-Type'] || options.headers['content-type']),
44 })
45 );
46 };
47
48 return req;
49 },
50 };
51
52 return {

Callers

nothing calls this directly

Calls 4

endMethod · 0.80
toStringMethod · 0.80
concatMethod · 0.80
fromMethod · 0.45

Tested by

no test coverage detected