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

Function request

tests/smoke/cjs/tests/error.smoke.test.cjs:11–53  ·  view source on GitHub ↗
(options, onResponse)

Source from the content-addressed store, hash-verified

9
10 return {
11 request(options, onResponse) {
12 const req = new EventEmitter();
13 req.destroyed = false;
14 req.write = () => true;
15 req.destroy = () => {
16 req.destroyed = true;
17 };
18 req.close = req.destroy;
19
20 req.setTimeout = (_ms, cb) => {
21 if (opts.timeout) {
22 req._timeoutCallback = cb;
23 }
24 };
25
26 req.end = () => {
27 if (opts.error) {
28 req.emit('error', opts.error);
29 return;
30 }
31
32 if (opts.timeout && req._timeoutCallback) {
33 req._timeoutCallback();
34 return;
35 }
36
37 const res = new PassThrough();
38 res.statusCode =
39 opts.response && opts.response.statusCode !== undefined ? opts.response.statusCode : 200;
40 res.statusMessage =
41 opts.response && opts.response.statusMessage ? opts.response.statusMessage : 'OK';
42 res.headers =
43 opts.response && opts.response.headers
44 ? opts.response.headers
45 : { 'content-type': 'application/json' };
46 res.req = req;
47
48 onResponse(res);
49 res.end(opts.response && opts.response.body ? opts.response.body : '{"ok":true}');
50 };
51
52 return req;
53 },
54 };
55};
56

Callers

nothing calls this directly

Calls 2

emitMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected