This commit is contained in:
Reinier Criel 2026-05-22 16:55:17 +08:00 committed by GitHub
commit 68d71b2e31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 93 additions and 25 deletions

View file

@ -68,21 +68,29 @@ function createHttpsServer(hostname, port, interceptor) {
return;
}
const pathAndQuery = getRequestPathAndQuery(req.url);
const targetUrl = `https://${hostname}${pathAndQuery}`;
try {
const pathAndQuery = getRequestPathAndQuery(req.url);
const targetUrl = `https://${hostname}${pathAndQuery}`;
const requestInterceptor = await interceptor.handleRequest(targetUrl);
const blockResponse = requestInterceptor.blockResponse;
const requestInterceptor = await interceptor.handleRequest(targetUrl);
const blockResponse = requestInterceptor.blockResponse;
if (blockResponse) {
ui.writeVerbose(`Safe-chain: Blocking request to ${targetUrl}`);
res.writeHead(blockResponse.statusCode, blockResponse.message);
res.end(blockResponse.message);
return;
if (blockResponse) {
ui.writeVerbose(`Safe-chain: Blocking request to ${targetUrl}`);
res.writeHead(blockResponse.statusCode, blockResponse.message);
res.end(blockResponse.message);
return;
}
// Collect request body
forwardRequest(req, hostname, port, res, requestInterceptor);
} catch (/** @type {any} */ error) {
ui.writeError(
`Safe-chain: Error handling request for ${req.url}: ${error.message}`
);
res.writeHead(502, "Bad Gateway");
res.end("Bad Gateway: Error handling request");
}
// Collect request body
forwardRequest(req, hostname, port, res, requestInterceptor);
}
const server = https.createServer(