Skip to content

SOCKS5h Proxy Example ​

Route HTTP client requests through a SOCKS5h proxy with remote DNS resolution. See examples/proxyDemo.zig.

zig
// Client-level proxy (URL form).
var client = httpx.Client.init(allocator, io, .{
    .proxy = "socks5h://127.0.0.1:1080",
});
defer client.deinit();

// Per-request proxy override.
var response = try client.get("http://target.example.com/data", .{
    .proxy = "socks5h://127.0.0.1:1080",
});
defer response.deinit();

socks5h:// delegates hostname resolution to the proxy; socks5:// resolves locally. http:// selects an HTTP forward proxy.

Expected Output ​

The snippet itself prints nothing; examples/proxyDemo.zig prints lines in this format (representative values shown):

text
Status: 200
Body length: 512

On failure it prints Proxy request failed: <ErrorName>. Statuses, lengths, and error names vary with the proxy and target.

Run ​

bash
zig build run-proxy-demo

What to Verify ​

  • Requests route through the configured proxy.
  • SOCKS5h performs DNS resolution on the proxy side (remote DNS).

Released under the MIT License.