Skip to content

HTTP client fails to make HTTPS requests via a proxy #19878

Description

@timothyqiu

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

  1. Run a local proxy server, say mitmdump
  2. Setup environment variables for http(s) proxy
    export https_proxy=http://127.0.0.1:8080
    
  3. Make sure the proxy server is setup correctly. For example curl https://httpbun.com/get should work and mitmdump should show the request.
  4. Then if you run this:
    const std = @import("std");
    
    pub fn main() !void {
        var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
        defer arena.deinit();
        const allocator = arena.allocator();
    
        var client = std.http.Client{ .allocator = allocator };
        defer client.deinit();
    
        client.initDefaultProxies(allocator) catch |err| {
            std.debug.print("Unable to initialize default proxies: {}\n", .{err});
        };
    
        var response = std.ArrayList(u8).init(allocator);
        defer response.deinit();
    
        // Can't use httpbin.org, see #14172.
        const result = try client.fetch(.{
            .method = .GET,
            .location = .{ .url = "https://httpbun.com/get" },
            .response_storage = .{ .dynamic = &response },
        });
        std.debug.print("Result: {}\n", .{result});
        std.debug.print("Response: {s}\n", .{response.items});
    }
  5. It's a bad request:
    Result: http.Client.FetchResult{ .status = http.Status.bad_request }
    Response: Client sent an HTTP request to an HTTPS server.
    

Expected Behavior

The request is successful, through the proxy.

Result: http.Client.FetchResult{ .status = http.Status.ok }
Response: {
  "method": "GET",
  "args": {},
  "headers": {
    "Accept-Encoding": "gzip, deflate",
    "Host": "httpbun.com",
    "User-Agent": "zig/0.12.0 (std.http)"
  },
  "origin": "123.456.789.012",
  "url": "http://httpbun.com/get",
  "form": {},
  "data": "",
  "json": null,
  "files": {}
}

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on May 7, 2024
  2. added
    standard libraryThis issue involves writing Zig code for the standard library.
    on Aug 14, 2024
  3. added this to the 0.16.0 milestone on Aug 14, 2024
  4. modified the milestones: 0.16.0, 0.15.0 on Feb 23, 2025
  5. added a commit that references this issue on May 16, 2025
  6. dacec354 commented on Nov 13, 2025

    @dacec354

    still not work?

  7. chardoncs commented on Nov 13, 2025

    @chardoncs

    No, apparently it's still WIP. You can only work around by temporarily unsetting proxy environment variables

    https_proxy='' http_proxy='' zig fetch --save <url>
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 behaviorstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions