fix(ai): honor NO_PROXY ports for secure websockets

This commit is contained in:
can1357
2026-07-16 03:11:02 +02:00
parent a17db4bea8
commit 8ff821515d
3 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ export function shouldBypassProxy(urlObj: URL): boolean {
.map(r => r.trim())
.filter(Boolean);
const targetHost = urlObj.hostname.toLowerCase();
const targetPort = urlObj.port || (urlObj.protocol === "https:" ? "443" : "80");
const targetPort = urlObj.port || (urlObj.protocol === "https:" || urlObj.protocol === "wss:" ? "443" : "80");
for (const rule of rules) {
if (rule === "*") {
+1 -1
View File
@@ -1466,7 +1466,7 @@ describe("openai-codex streaming", () => {
it("bypasses configured proxies for NO_PROXY websocket targets", async () => {
Bun.env.PI_PROXY_CODEX_PROXY_TEST = "http://127.0.0.1:7890";
Bun.env.NO_PROXY = "chatgpt.com";
Bun.env.NO_PROXY = "chatgpt.com:443";
__resetProxyCache();
let capturedProxy: string | undefined;
class NoProxyWebSocket extends MockWebSocket {
+5
View File
@@ -190,6 +190,11 @@ describe("shouldBypassProxy NO_PROXY rules", () => {
expect(shouldBypassProxy(new URL("https://api.sakana.ai/v1"))).toBe(false);
expect(shouldBypassProxy(new URL("http://api.sakana.ai:8080/v1"))).toBe(true);
});
it("uses port 443 for secure websocket targets", () => {
Bun.env.NO_PROXY = "api.sakana.ai:443";
expect(shouldBypassProxy(new URL("wss://api.sakana.ai/v1"))).toBe(true);
});
});
describe("wrapFetchForProxy", () => {