mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-04-04 00:20:32 +00:00
fix WebBotAuthLayer crash
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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));
|
||||||
|
var our_req = req;
|
||||||
|
|
||||||
if (self.auth == null) {
|
if (ctx.network.web_bot_auth) |*wba| {
|
||||||
return self.next.request(ctx, req);
|
|
||||||
}
|
|
||||||
|
|
||||||
const arena = try ctx.network.app.arena_pool.acquire(.{ .debug = "WebBotAuthLayer" });
|
const arena = try ctx.network.app.arena_pool.acquire(.{ .debug = "WebBotAuthLayer" });
|
||||||
defer ctx.network.app.arena_pool.release(arena);
|
defer ctx.network.app.arena_pool.release(arena);
|
||||||
|
|
||||||
var our_req = req;
|
|
||||||
const authority = URL.getHost(req.url);
|
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);
|
return self.next.request(ctx, our_req);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user