mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-09 18:24:54 +00:00
fix(proxy): honor backpressure in cliproxy local streaming (#1379)
This commit is contained in:
@@ -116,9 +116,22 @@ export function createCliproxyLocalProxyRouter(deps: CliproxyLocalProxyDeps = {}
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.writeHead(proxyStatus, proxyRes.headers);
|
res.writeHead(proxyStatus, proxyRes.headers);
|
||||||
// Manual streaming instead of pipe() for Bun runtime compatibility
|
// Manual streaming instead of pipe() for Bun runtime compatibility.
|
||||||
proxyRes.on('data', (chunk: Buffer) => res.write(chunk));
|
// Explicitly honor downstream backpressure to avoid unbounded buffering.
|
||||||
proxyRes.on('end', () => res.end());
|
const onDrain = () => proxyRes.resume();
|
||||||
|
|
||||||
|
proxyRes.on('data', (chunk: Buffer) => {
|
||||||
|
const canContinue = res.write(chunk);
|
||||||
|
if (!canContinue) {
|
||||||
|
proxyRes.pause();
|
||||||
|
res.once('drain', onDrain);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
proxyRes.on('end', () => {
|
||||||
|
res.off('drain', onDrain);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user