fix WebBotAuthLayer crash

This commit is contained in:
Muki Kiboigo
2026-04-03 13:31:10 -07:00
parent 3385ce2586
commit de4f91af01
2 changed files with 10 additions and 17 deletions

View File

@@ -659,9 +659,7 @@ pub fn init(allocator: Allocator, network: *Network) !*Client {
.allocator = allocator,
.pending = .empty,
},
WebBotAuthLayer{
.auth = if (network.web_bot_auth) |*wba| wba else null,
},
WebBotAuthLayer{},
CacheLayer{},
});
errdefer layers.deinit(allocator);

View File

@@ -28,7 +28,6 @@ const Layer = @import("../../browser/HttpClient.zig").Layer;
const WebBotAuthLayer = @This();
next: Layer = undefined,
auth: ?*WebBotAuth,
pub fn layer(self: *WebBotAuthLayer) Layer {
return .{
@@ -37,23 +36,19 @@ pub fn layer(self: *WebBotAuthLayer) Layer {
};
}
pub fn deinit(self: *WebBotAuthLayer, allocator: std.mem.Allocator) void {
if (self.auth) |wba| wba.deinit(allocator);
}
pub fn deinit(_: *WebBotAuthLayer, _: std.mem.Allocator) void {}
fn request(ptr: *anyopaque, ctx: Context, req: Request) anyerror!void {
const self: *WebBotAuthLayer = @ptrCast(@alignCast(ptr));
var our_req = req;
if (self.auth == null) {
return self.next.request(ctx, req);
}
if (ctx.network.web_bot_auth) |*wba| {
const arena = try ctx.network.app.arena_pool.acquire(.{ .debug = "WebBotAuthLayer" });
defer ctx.network.app.arena_pool.release(arena);
var our_req = req;
const authority = URL.getHost(req.url);
try self.auth.?.signRequest(arena, &our_req.headers, authority);
try wba.signRequest(arena, &our_req.headers, authority);
}
return self.next.request(ctx, our_req);
}