add proxy support to Cloudflare

This commit is contained in:
Emil Lerch 2023-10-25 09:19:06 -07:00
parent 02df7a1c75
commit 878f62ef0a
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 26 additions and 7 deletions

View File

@ -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));

View File

@ -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);