1import http from 'http';
2import zlib from 'zlib';
3
4const options = {
5 hostname: 'localhost',
6 port: 3000,
7 path: '/trap',
8 method: 'GET',
9 headers: {
10 'Accept-Encoding': 'gzip, deflate'
11 }
12};
13
14const req = http.request(options, res => {
15 console.log(`STATUS: ${res.statusCode}`);
16 console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
17
18 const gunzip = zlib.createGunzip();
19 let totalSize = 0;
20
21 res.pipe(gunzip);
22
23 gunzip.on('data', chunk => {
24 totalSize += chunk.length;
25 console.log(`Decompressed ${totalSize / (1024 * 1024)} MB...`);
26 if (totalSize > 1024 * 1024 * 500) { // Simulate crashing at 500MB
27 console.log("💥 Bot crashed! Out of memory.");
28 req.destroy();
29 }
30 });
31
32 gunzip.on('end', () => {
33 console.log('Decompression complete.');
34 });
35});
36
37req.on('error', e => {
38 console.error(`problem with request: ${e.message}`);
39});
40
41req.end();