diff options
Diffstat (limited to 'src/env_loader.zig')
-rw-r--r-- | src/env_loader.zig | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/env_loader.zig b/src/env_loader.zig index 3b8633c4f..5d8fa4873 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -14,6 +14,7 @@ const C = bun.C; const CodepointIterator = @import("./string_immutable.zig").CodepointIterator; const Analytics = @import("./analytics/analytics_thread.zig"); const Fs = @import("./fs.zig"); +const URL = @import("./url.zig").URL; const Api = @import("./api/schema.zig").Api; const which = @import("./which.zig").which; const Variable = struct { @@ -431,6 +432,46 @@ pub const Loader = struct { this.map.get("bamboo.buildKey")) != null; } + pub fn getHttpProxy(this: *Loader, url: URL) ?URL { + // TODO: When Web Worker support is added, make sure to intern these strings + var http_proxy: ?URL = null; + + 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); + } + } else { + if (this.map.get("https_proxy") orelse this.map.get("HTTPS_PROXY")) |proxy| { + if (proxy.len > 0) 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; + + var no_proxy_list = std.mem.split(u8, no_proxy_text, ","); + var next = no_proxy_list.next(); + while (next != null) { + var host = next.?; + if (strings.eql(host, "*")) { + return null; + } + //strips . + if (host[0] == '.') { + host = host[1.. :0]; + } + //hostname ends with suffix + if (strings.endsWith(url.hostname, host)) { + return null; + } + next = no_proxy_list.next(); + } + } + } + return http_proxy; + } pub fn loadNodeJSConfig(this: *Loader, fs: *Fs.FileSystem, override_node: []const u8) !bool { var buf: Fs.PathBuffer = undefined; |