Skip to content

Commit b3be6d0

Browse files
committed
fix(proxy): allow empty string http_proxy env.
Close: #5380
1 parent 92f2d9a commit b3be6d0

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/env_loader.zig

+9-3
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,24 @@ pub const Loader = struct {
102102

103103
if (url.isHTTP()) {
104104
if (this.map.get("http_proxy") orelse this.map.get("HTTP_PROXY")) |proxy| {
105-
if (proxy.len > 0) http_proxy = URL.parse(proxy);
105+
if (proxy.len > 0 and !strings.eqlComptime(proxy, "\"\"") and !strings.eqlComptime(proxy, "''")) {
106+
http_proxy = URL.parse(proxy);
107+
}
106108
}
107109
} else {
108110
if (this.map.get("https_proxy") orelse this.map.get("HTTPS_PROXY")) |proxy| {
109-
if (proxy.len > 0) http_proxy = URL.parse(proxy);
111+
if (proxy.len > 0 and !strings.eqlComptime(proxy, "\"\"") and !strings.eqlComptime(proxy, "''")) {
112+
http_proxy = URL.parse(proxy);
113+
}
110114
}
111115
}
112116

113117
// NO_PROXY filter
114118
if (http_proxy != null) {
115119
if (this.map.get("no_proxy") orelse this.map.get("NO_PROXY")) |no_proxy_text| {
116-
if (no_proxy_text.len == 0) return http_proxy;
120+
if (no_proxy_text.len == 0 or strings.eqlComptime(no_proxy_text, "\"\"") or strings.eqlComptime(no_proxy_text, "''")) {
121+
return http_proxy;
122+
}
117123

118124
var no_proxy_list = std.mem.split(u8, no_proxy_text, ",");
119125
var next = no_proxy_list.next();

test/js/bun/http/proxy.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
22
import { gc } from "harness";
33
import fs from "fs";
4+
import { tmpdir } from "os";
45
import path from "path";
6+
import { bunExe } from "harness";
57

68
let proxy, auth_proxy, server;
79

@@ -168,3 +170,30 @@ it("proxy non-TLS auth can fail", async () => {
168170
}
169171
}
170172
});
173+
174+
it.each([
175+
[undefined, undefined],
176+
["", ""],
177+
["''", "''"],
178+
['""', '""'],
179+
])("test proxy env, http_proxy=%s https_proxy=%s", async (http_proxy, https_proxy) => {
180+
const path = `${tmpdir()}/bun-test-http-proxy-env-${Date.now()}.ts`;
181+
fs.writeFileSync(path, 'await fetch("https://example.com");');
182+
183+
const { stdout, stderr, exitCode } = Bun.spawnSync({
184+
cmd: [bunExe(), "run", path],
185+
env: {
186+
http_proxy: http_proxy,
187+
https_proxy: https_proxy,
188+
},
189+
stdout: "pipe",
190+
stderr: "pipe",
191+
});
192+
193+
try {
194+
expect(stderr.includes("FailedToOpenSocket: Was there a typo in the url or port?")).toBe(false);
195+
expect(exitCode).toBe(0);
196+
} finally {
197+
fs.unlinkSync(path);
198+
}
199+
});

0 commit comments

Comments
 (0)