| 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 { |