From 878f62ef0acf97f2c5eb1ed55025b90d7fd6e354 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 25 Oct 2023 09:19:06 -0700 Subject: [PATCH] add proxy support to Cloudflare --- src/CloudflareDeployStep.zig | 13 +++++++++++++ src/cloudflaredeploy.zig | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/CloudflareDeployStep.zig b/src/CloudflareDeployStep.zig index b186193..445454d 100644 --- a/src/CloudflareDeployStep.zig +++ b/src/CloudflareDeployStep.zig @@ -55,6 +55,19 @@ fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void { var client = std.http.Client{ .allocator = b.allocator }; defer client.deinit(); + var proxy_text = std.os.getenv("https_proxy") orelse std.os.getenv("HTTPS_PROXY"); + if (proxy_text) |p| { + client.deinit(); + const proxy = try std.Uri.parse(p); + client = std.http.Client{ + .allocator = b.allocator, + .proxy = .{ + .protocol = if (std.ascii.eqlIgnoreCase(proxy.scheme, "http")) .plain else .tls, + .host = proxy.host.?, + .port = proxy.port, + }, + }; + } const script = self.options.primary_file_data orelse try std.fs.cwd().readFileAlloc(b.allocator, self.primary_javascript_file.path, std.math.maxInt(usize)); diff --git a/src/cloudflaredeploy.zig b/src/cloudflaredeploy.zig index 03b02ff..fa791ab 100644 --- a/src/cloudflaredeploy.zig +++ b/src/cloudflaredeploy.zig @@ -13,13 +13,19 @@ pub fn main() !u8 { const allocator = arena.allocator(); var client = std.http.Client{ .allocator = allocator }; defer client.deinit(); - // .allocator = allocator, - // .proxy = .{ - // .protocol = .plain, - // .host = "localhost", - // .port = 8080, - // }, - // }; + var proxy_text = std.os.getenv("https_proxy") orelse std.os.getenv("HTTPS_PROXY"); + if (proxy_text) |p| { + client.deinit(); + const proxy = try std.Uri.parse(p); + client = std.http.Client{ + .allocator = allocator, + .proxy = .{ + .protocol = if (std.ascii.eqlIgnoreCase(proxy.scheme, "http")) .plain else .tls, + .host = proxy.host.?, + .port = proxy.port, + }, + }; + } const stdout_file = std.io.getStdOut().writer(); var bw = std.io.bufferedWriter(stdout_file);