-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_http.zig
More file actions
35 lines (25 loc) · 1021 Bytes
/
test_http.zig
File metadata and controls
35 lines (25 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var client = std.http.Client{ .allocator = allocator };
defer client.deinit();
var body_buf = std.ArrayList(u8).empty;
defer body_buf.deinit(allocator);
const uri = try std.Uri.parse("https://httpbin.org/get");
var req = try client.request(.GET, uri, .{
.headers = .{
.user_agent = .{ .override = "codex-cli" },
.accept_encoding = .omit,
},
});
defer req.deinit();
try req.sendBodiless();
var redirect_buf: [2048]u8 = undefined;
var response = try req.receiveHead(&redirect_buf);
var transfer_buf: [4096]u8 = undefined;
var body_reader = response.reader(&transfer_buf);
try body_reader.appendRemaining(allocator, &body_buf, std.io.Limit.unlimited);
std.debug.print("Status: {d}\nBody: {s}\n", .{ response.head.status, body_buf.items });
}