replace zig-async-io and std.http.Client with a custom HTTP client

This commit is contained in:
Karl Seguin
2025-03-14 19:40:56 +08:00
parent fd35724aa8
commit 2017d4785b
17 changed files with 1566 additions and 2145 deletions

View File

@@ -30,8 +30,8 @@ pub fn expectEqual(expected: anytype, actual: anytype) !void {
return;
},
.optional => {
if (actual == null) {
return std.testing.expectEqual(null, expected);
if (@typeInfo(@TypeOf(expected)) == .null) {
return std.testing.expectEqual(null, actual);
}
return expectEqual(expected, actual.?);
},
@@ -141,3 +141,36 @@ pub fn print(comptime fmt: []const u8, args: anytype) void {
pub fn app(_: anytype) *App {
return App.init(allocator, .serve) catch unreachable;
}
pub const Random = struct {
var instance: ?std.Random.DefaultPrng = null;
pub fn fill(buf: []u8) void {
var r = random();
r.bytes(buf);
}
pub fn fillAtLeast(buf: []u8, min: usize) []u8 {
var r = random();
const l = r.intRangeAtMost(usize, min, buf.len);
r.bytes(buf[0..l]);
return buf;
}
pub fn intRange(comptime T: type, min: T, max: T) T {
var r = random();
return r.intRangeAtMost(T, min, max);
}
pub fn random() std.Random {
if (instance == null) {
var seed: u64 = undefined;
std.posix.getrandom(std.mem.asBytes(&seed)) catch unreachable;
instance = std.Random.DefaultPrng.init(seed);
// instance = std.Random.DefaultPrng.init(0);
}
return instance.?.random();
}
};
>>>>>>> eaccbd0 (replace zig-async-io and std.http.Client with a custom HTTP client)