forked from StellarFlow-Network/stellarflow-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-compression.js
More file actions
41 lines (36 loc) · 1.27 KB
/
Copy pathverify-compression.js
File metadata and controls
41 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const http = require('http');
const https = require('https');
const zlib = require('zlib');
const url = 'http://localhost:3000/api/price-feed/ngn-xlm'; // Adjust URL as needed
async function verifyCompression(encoding) {
console.log(`\n--- Verifying with Accept-Encoding: ${encoding} ---`);
const client = url.startsWith('https') ? https : http;
return new Promise((resolve, reject) => {
const req = client.get(
url,
{
headers: {
'Accept-Encoding': encoding,
},
},
(res) => {
console.log(`Status Code: ${res.statusCode}`);
console.log(`Content-Encoding: ${res.headers['content-encoding'] || 'None'}`);
console.log(`Content-Type: ${res.headers['content-type'] || 'None'}`);
console.log(`Content-Length (compressed): ${res.headers['content-length'] || 'N/A'}`);
let rawData = Buffer.from([]);
res.on('data', (chunk) => (rawData = Buffer.concat([rawData, chunk])));
res.on('end', () => {
console.log(`Body size (compressed): ${rawData.length} bytes`);
resolve();
});
}
);
req.on('error', reject);
});
}
(async () => {
await verifyCompression('gzip');
await verifyCompression('br');
await verifyCompression('gzip, deflate, br');
})();