aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-09-15 20:24:03 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-15 05:24:03 -0700
commit7d0db82bb3b1ac0ecd2fcc42e85734a588968112 (patch)
tree7a9da72a299b6a39313fe93c6652b4f57634bb7a
parent4b00144211b5c65aba1d693c6b9a51763b58567d (diff)
downloadbun-7d0db82bb3b1ac0ecd2fcc42e85734a588968112.tar.gz
bun-7d0db82bb3b1ac0ecd2fcc42e85734a588968112.tar.zst
bun-7d0db82bb3b1ac0ecd2fcc42e85734a588968112.zip
fix(proxy): allow empty string `http_proxy` env. (#5464)
Close: #5380
-rw-r--r--src/env_loader.zig12
-rw-r--r--test/js/bun/http/proxy.test.js29
2 files changed, 38 insertions, 3 deletions
diff --git a/src/env_loader.zig b/src/env_loader.zig
index 9d0c69d04..2d467371a 100644
--- a/src/env_loader.zig
+++ b/src/env_loader.zig
@@ -102,18 +102,24 @@ pub const Loader = struct {
if (url.isHTTP()) {
if (this.map.get("http_proxy") orelse this.map.get("HTTP_PROXY")) |proxy| {
- if (proxy.len > 0) http_proxy = URL.parse(proxy);
+ if (proxy.len > 0 and !strings.eqlComptime(proxy, "\"\"") and !strings.eqlComptime(proxy, "''")) {
+ http_proxy = URL.parse(proxy);
+ }
}
} else {
if (this.map.get("https_proxy") orelse this.map.get("HTTPS_PROXY")) |proxy| {
- if (proxy.len > 0) http_proxy = URL.parse(proxy);
+ if (proxy.len > 0 and !strings.eqlComptime(proxy, "\"\"") and !strings.eqlComptime(proxy, "''")) {
+ http_proxy = URL.parse(proxy);
+ }
}
}
// NO_PROXY filter
if (http_proxy != null) {
if (this.map.get("no_proxy") orelse this.map.get("NO_PROXY")) |no_proxy_text| {
- if (no_proxy_text.len == 0) return http_proxy;
+ if (no_proxy_text.len == 0 or strings.eqlComptime(no_proxy_text, "\"\"") or strings.eqlComptime(no_proxy_text, "''")) {
+ return http_proxy;
+ }
var no_proxy_list = std.mem.split(u8, no_proxy_text, ",");
var next = no_proxy_list.next();
diff --git a/test/js/bun/http/proxy.test.js b/test/js/bun/http/proxy.test.js
index 48595a2ac..433adfb83 100644
--- a/test/js/bun/http/proxy.test.js
+++ b/test/js/bun/http/proxy.test.js
@@ -1,7 +1,9 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import { gc } from "harness";
import fs from "fs";
+import { tmpdir } from "os";
import path from "path";
+import { bunExe } from "harness";
let proxy, auth_proxy, server;
@@ -168,3 +170,30 @@ it("proxy non-TLS auth can fail", async () => {
}
}
});
+
+it.each([
+ [undefined, undefined],
+ ["", ""],
+ ["''", "''"],
+ ['""', '""'],
+])("test proxy env, http_proxy=%s https_proxy=%s", async (http_proxy, https_proxy) => {
+ const path = `${tmpdir()}/bun-test-http-proxy-env-${Date.now()}.ts`;
+ fs.writeFileSync(path, 'await fetch("https://example.com");');
+
+ const { stdout, stderr, exitCode } = Bun.spawnSync({
+ cmd: [bunExe(), "run", path],
+ env: {
+ http_proxy: http_proxy,
+ https_proxy: https_proxy,
+ },
+ stdout: "pipe",
+ stderr: "pipe",
+ });
+
+ try {
+ expect(stderr.includes("FailedToOpenSocket: Was there a typo in the url or port?")).toBe(false);
+ expect(exitCode).toBe(0);
+ } finally {
+ fs.unlinkSync(path);
+ }
+});