Add upstream proxy support

This commit is contained in:
Sander Declerck 2025-10-02 09:06:35 +02:00
parent 60543308f4
commit a6980d5108
No known key found for this signature in database
4 changed files with 76 additions and 0 deletions

View file

@ -1,5 +1,6 @@
import https from "https";
import { generateCertForHost } from "./certUtils.js";
import { HttpsProxyAgent } from "https-proxy-agent";
export function mitmConnect(req, clientSocket, isAllowed) {
const { hostname } = new URL(`http://${req.url}`);
@ -75,6 +76,11 @@ function createProxyRequest(hostname, req, res) {
delete options.headers.host;
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
if (httpsProxy) {
options.agent = new HttpsProxyAgent(httpsProxy);
}
const proxyReq = https.request(options, (proxyRes) => {
res.writeHead(proxyRes.statusCode, proxyRes.headers);
proxyRes.pipe(res);