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, .allocator = allocator,
.pending = .empty, .pending = .empty,
}, },
WebBotAuthLayer{ WebBotAuthLayer{},
.auth = if (network.web_bot_auth) |*wba| wba else null,
},
CacheLayer{}, CacheLayer{},
}); });
errdefer layers.deinit(allocator); errdefer layers.deinit(allocator);

View File

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