diff --git a/assistant/src/module/assistant/proxy/http-proxy.ts b/assistant/src/module/assistant/proxy/http-proxy.ts index 8e5036d..57d4101 100644 --- a/assistant/src/module/assistant/proxy/http-proxy.ts +++ b/assistant/src/module/assistant/proxy/http-proxy.ts @@ -81,16 +81,23 @@ export const httpProxy = (req: http.IncomingMessage, res: http.ServerResponse, p // @ts-ignore options.rejectUnauthorized = false; // 忽略证书错误 } - + if (res.headersSent) { + return; + } // 创建代理请求 const proxyReq = httpProxy.request(options, (proxyRes) => { - // Modify the 'set-cookie' headers using rewriteCookieDomain - if (proxyRes.headers['set-cookie']) { - proxyRes.headers['set-cookie'] = proxyRes.headers['set-cookie'].map((cookie) => rewriteCookieDomain(cookie, cookieHost)); - console.log('rewritten set-cookie:', proxyRes.headers['set-cookie']); + // 检查响应头是否已经发送 + if (res.headersSent) { + return; + } + // 复制响应头并修改 'set-cookie' + const responseHeaders = { ...proxyRes.headers }; + if (responseHeaders['set-cookie']) { + responseHeaders['set-cookie'] = responseHeaders['set-cookie'].map((cookie) => rewriteCookieDomain(cookie, cookieHost)); + console.log('rewritten set-cookie:', responseHeaders['set-cookie']); } // 将代理服务器的响应头和状态码返回给客户端 - res.writeHead(proxyRes.statusCode, proxyRes.headers); + res.writeHead(proxyRes.statusCode, responseHeaders); // 将代理响应流写入客户端响应 proxyRes.pipe(res, { end: true }); });