Verify explicit activation and legacy incremental migration

This commit is contained in:
Jonathan Sykes
2026-10-08 00:03:14 +08:00
parent bb446c717f
commit 5d1e5ec791
7 changed files with 96 additions and 16 deletions

View File

@@ -48,6 +48,7 @@ export function categorizeContentType(contentType, urlPath) {
export function createThrottleProxy({ targetPort, profile = 'lte' }) {
let activeTracking = false;
let requestCount = 0;
let requests = [];
let totalWireBytes = 0;
let bytesByType = {
html: 0,
@@ -110,8 +111,11 @@ export function createThrottleProxy({ targetPort, profile = 'lte' }) {
const ct = upRes.headers['content-type'] || '';
const cat = categorizeContentType(ct, pathname);
let recorded;
if (activeTracking) {
requestCount++;
recorded={url:clientReq.url,status:upRes.statusCode,bytes:0};
requests.push(recorded);
}
clientRes.writeHead(upRes.statusCode, upRes.headers);
@@ -120,6 +124,7 @@ export function createThrottleProxy({ targetPort, profile = 'lte' }) {
upRes.on('data', (chunk) => {
if (activeTracking) {
totalWireBytes += chunk.length;
if(recorded) recorded.bytes += chunk.length;
bytesByType[cat] = (bytesByType[cat] || 0) + chunk.length;
}
clientRes.write(chunk);
@@ -131,6 +136,7 @@ export function createThrottleProxy({ targetPort, profile = 'lte' }) {
throttler.on('data', (chunk) => {
if (activeTracking) {
totalWireBytes += chunk.length;
if(recorded) recorded.bytes += chunk.length;
bytesByType[cat] = (bytesByType[cat] || 0) + chunk.length;
}
});
@@ -176,7 +182,7 @@ export function createThrottleProxy({ targetPort, profile = 'lte' }) {
activeTracking = false;
},
resetStats: () => {
requestCount = 0;
requestCount = 0; requests = [];
totalWireBytes = 0;
bytesByType = {
html: 0,
@@ -193,7 +199,7 @@ export function createThrottleProxy({ targetPort, profile = 'lte' }) {
isOfflineMode = !!val;
},
getStats: () => ({
requestCount,
requestCount, requests,
totalWireBytes,
bytesByType: { ...bytesByType },
}),