@skrillex1224/playwright-toolkit 3.0.9 → 3.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +59 -83
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +60 -84
- package/dist/index.js.map +4 -4
- package/dist/internals/proxy-meter.js +5 -51
- package/package.json +1 -1
|
@@ -32,25 +32,6 @@ const state = {
|
|
|
32
32
|
: null,
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
const formatFatalError = (error) => {
|
|
36
|
-
if (error instanceof Error) {
|
|
37
|
-
return error.stack || error.message || String(error);
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
return JSON.stringify(error);
|
|
41
|
-
} catch {
|
|
42
|
-
return String(error);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const exitAfterFatal = (kind, error) => {
|
|
47
|
-
try {
|
|
48
|
-
console.error(`[proxy-meter] fatal ${kind}: ${formatFatalError(error)}`);
|
|
49
|
-
} catch {}
|
|
50
|
-
flushSnapshot();
|
|
51
|
-
process.exit(1);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
35
|
const getHostBucket = (host) => {
|
|
55
36
|
if (!host) return null;
|
|
56
37
|
if (!state.hosts[host]) {
|
|
@@ -79,21 +60,6 @@ const safeError = (error) => {
|
|
|
79
60
|
return message.length > 240 ? message.slice(0, 240) : message;
|
|
80
61
|
};
|
|
81
62
|
|
|
82
|
-
const sendBadGateway = (res, error = null) => {
|
|
83
|
-
if (!res || res.destroyed || res.writableEnded) return;
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
if (!res.headersSent) {
|
|
87
|
-
res.writeHead(502);
|
|
88
|
-
res.end('Bad Gateway');
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Headers are already committed; the only truthful error signal left is closing the stream.
|
|
93
|
-
res.destroy(error instanceof Error ? error : undefined);
|
|
94
|
-
} catch {}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
63
|
const statusLabel = (statusCode, error) => {
|
|
98
64
|
const code = Number(statusCode) || 0;
|
|
99
65
|
if (error || code <= 0) return 'ERR';
|
|
@@ -383,7 +349,8 @@ const forwardHttp = (req, res) => {
|
|
|
383
349
|
|
|
384
350
|
if (!target) {
|
|
385
351
|
tracker.close({ statusCode: 0, error: 'invalid_target_url' });
|
|
386
|
-
|
|
352
|
+
res.writeHead(502);
|
|
353
|
+
res.end('Bad Gateway');
|
|
387
354
|
return;
|
|
388
355
|
}
|
|
389
356
|
|
|
@@ -414,19 +381,7 @@ const forwardHttp = (req, res) => {
|
|
|
414
381
|
let responseStatus = 0;
|
|
415
382
|
const proxyReq = http.request(requestOptions, (proxyRes) => {
|
|
416
383
|
responseStatus = Number(proxyRes.statusCode) || 0;
|
|
417
|
-
|
|
418
|
-
tracker.close({ statusCode: responseStatus || 499, error: 'client_response_closed' });
|
|
419
|
-
proxyRes.resume();
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
try {
|
|
423
|
-
res.writeHead(responseStatus || 502, proxyRes.headers);
|
|
424
|
-
} catch (error) {
|
|
425
|
-
tracker.close({ statusCode: responseStatus, error: safeError(error) });
|
|
426
|
-
proxyRes.resume();
|
|
427
|
-
sendBadGateway(res, error);
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
384
|
+
res.writeHead(responseStatus || 502, proxyRes.headers);
|
|
430
385
|
proxyRes.on('data', (chunk) => {
|
|
431
386
|
const size = chunk?.length || 0;
|
|
432
387
|
addTraffic(hostname, 'in', size);
|
|
@@ -457,7 +412,8 @@ const forwardHttp = (req, res) => {
|
|
|
457
412
|
|
|
458
413
|
proxyReq.on('error', (error) => {
|
|
459
414
|
tracker.close({ statusCode: responseStatus, error: safeError(error) });
|
|
460
|
-
|
|
415
|
+
res.writeHead(502);
|
|
416
|
+
res.end('Bad Gateway');
|
|
461
417
|
});
|
|
462
418
|
};
|
|
463
419
|
|
|
@@ -589,7 +545,5 @@ const shutdown = () => {
|
|
|
589
545
|
process.exit(0);
|
|
590
546
|
};
|
|
591
547
|
|
|
592
|
-
process.on('uncaughtException', (error) => exitAfterFatal('uncaughtException', error));
|
|
593
|
-
process.on('unhandledRejection', (error) => exitAfterFatal('unhandledRejection', error));
|
|
594
548
|
process.on('SIGINT', shutdown);
|
|
595
549
|
process.on('SIGTERM', shutdown);
|