mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user