Skip to content

Using zig build on macOS fails to fetch remote repositories through a proxy. #25996

Description

@xuanluoya

Zig Version

0.15.2 brew, the latest

Steps to Reproduce and Observed Behavior

Just use zig build in any Zig project that requires remote packages.

Expected Behavior

Just use zig build for any

build.zig.zon:8:20: error: unable to discover remote git server capabilities: HttpConnectionClosing
            .url = "git+https://github.com/Hejsil/zig-clap.git#5289e0753cd274d65344bef1c114284c633536ea",

I tried to remove https and use http

build.zig.zon:8:20: error: unable to discover remote git server capabilities: HttpConnectionClosing
            .url = "git+http://github.com/Hejsil/zig-clap.git#5289e0753cd274d65344bef1c114284c633536ea",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Still not working. This problem has actually existed for a long time, present since the early versions of the package manager. This is also one of the reasons blocking me from learning Zig. I've been trying to solve it, but haven't found a solution. It seems Zig will never use a proxy channel...

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on Nov 21, 2025
  2. mrjbq7 commented on Nov 21, 2025

    @mrjbq7
    Contributor

    I can't reproduce that locally, but I'm not using a proxy -- how is yours configured?

  3. MatthiasPortzel commented on Nov 21, 2025

    @MatthiasPortzel
  4. xuanluoya commented on Nov 22, 2025

    @xuanluoya
    Author

    I can't reproduce that locally, but I'm not using a proxy -- how is yours configured?

    Just normally opening the VPN and setting up the proxy on the terminal. look like:

    export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

    In the current environment, only zig shows similar symptoms; other programs all obediently go through the proxy.

  5. xuanluoya commented on Nov 22, 2025

    @xuanluoya
    Author
  6. xuanluoya commented on Nov 22, 2025

    @xuanluoya
    Author

    #19878

    🤔To be precise, the HTTP request seems to be working; I tested it and there were no errors.

    From zig cookbook

    const std = @import("std");
    const print = std.debug.print;
    const http = std.http;
    
    pub fn main() !void {
        var gpa = std.heap.GeneralPurposeAllocator(.{}){};
        defer _ = gpa.deinit();
        const allocator = gpa.allocator();
    
        var client = http.Client{ .allocator = allocator };
        defer client.deinit();
    
        const uri = try std.Uri.parse("http://httpbin.org/get");
        var req = try client.request(.GET, uri, .{
            .extra_headers = &.{.{ .name = "Custom-header", .value = "Custom Value" }},
        });
        defer req.deinit();
    
        try req.sendBodiless();
    
        var redirect_buffer: [1024]u8 = undefined;
        var response = try req.receiveHead(&redirect_buffer);
        var iter = response.head.iterateHeaders();
        while (iter.next()) |header| {
            std.debug.print("Name:{s}, Value:{s}\n", .{ header.name, header.value });
        }
    
        try std.testing.expectEqual(response.head.status, .ok);
        const body = try response.reader(&.{}).allocRemaining(allocator, .unlimited);
        defer allocator.free(body);
    
        print("Body:\n{s}\n", .{body});
    }
    

    Request:

    Name:Date, Value:Sat, 22 Nov 2025 09:30:48 GMT
    Name:Content-Type, Value:application/json
    Name:Content-Length, Value:322
    Name:Connection, Value:keep-alive
    Name:Server, Value:gunicorn/19.9.0
    Name:Access-Control-Allow-Origin, Value:*
    Name:Access-Control-Allow-Credentials, Value:true
    Body:
    {
      "args": {},
      "headers": {
        "Accept-Encoding": "gzip, deflate",
        "Custom-Header": "Custom Value",
        "Host": "httpbin.org",
        "User-Agent": "zig/0.15.2 (std.http)",
        "X-Amzn-Trace-Id": "Root=1-692182c6-57f76ceb27623ce05bb2be96"
      },
      "origin": "222.187.201.70",
      "url": "http://httpbin.org/get"
    }
    

    Actually, for a while, dvui could be successfully compiled after I opened the VPN, even though it needed to access the remote repository, but now it doesn't work anymore. This is indeed strange.🤔

  7. xuanluoya commented on Nov 22, 2025

    @xuanluoya
    Author

    I tried compiling pixi again, but it seems that a miracle didn't happen...

    ( ˘•ω•˘ )

    zig build
    pixi/build.zig.zon:30:20: error: unable to discover remote git server capabilities: HttpConnectionClosing
                .url = "git+https://github.com/foxnne/dvui-dev#77bded1a0b46fc44879c694bbbfc3f379b55ed68",
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions