mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-05 14:57:11 +00:00
use RobotsRequestContext deinit
This commit is contained in:
@@ -284,6 +284,12 @@ const RobotsRequestContext = struct {
|
|||||||
robots_url: [:0]const u8,
|
robots_url: [:0]const u8,
|
||||||
buffer: std.ArrayList(u8),
|
buffer: std.ArrayList(u8),
|
||||||
status: u16 = 0,
|
status: u16 = 0,
|
||||||
|
|
||||||
|
pub fn deinit(self: *RobotsRequestContext) void {
|
||||||
|
self.client.allocator.free(self.robots_url);
|
||||||
|
self.buffer.deinit(self.client.allocator);
|
||||||
|
self.client.allocator.destroy(self);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn fetchRobotsThenProcessRequest(self: *Client, robots_url: [:0]const u8, req: Request) !void {
|
fn fetchRobotsThenProcessRequest(self: *Client, robots_url: [:0]const u8, req: Request) !void {
|
||||||
@@ -332,9 +338,7 @@ fn robotsDataCallback(transfer: *Http.Transfer, data: []const u8) !void {
|
|||||||
|
|
||||||
fn robotsDoneCallback(ctx_ptr: *anyopaque) !void {
|
fn robotsDoneCallback(ctx_ptr: *anyopaque) !void {
|
||||||
const ctx: *RobotsRequestContext = @ptrCast(@alignCast(ctx_ptr));
|
const ctx: *RobotsRequestContext = @ptrCast(@alignCast(ctx_ptr));
|
||||||
defer ctx.client.allocator.destroy(ctx);
|
defer ctx.deinit();
|
||||||
defer ctx.buffer.deinit(ctx.client.allocator);
|
|
||||||
defer ctx.client.allocator.free(ctx.robots_url);
|
|
||||||
|
|
||||||
var allowed = true;
|
var allowed = true;
|
||||||
|
|
||||||
@@ -348,10 +352,7 @@ fn robotsDoneCallback(ctx_ptr: *anyopaque) !void {
|
|||||||
|
|
||||||
const path = URL.getPathname(ctx.req.url);
|
const path = URL.getPathname(ctx.req.url);
|
||||||
allowed = robots.isAllowed(path);
|
allowed = robots.isAllowed(path);
|
||||||
}
|
} else if (ctx.status == 404) {
|
||||||
|
|
||||||
// If not found, store as Not Found.
|
|
||||||
if (ctx.status == 404) {
|
|
||||||
log.debug(.http, "robots not found", .{ .url = ctx.robots_url });
|
log.debug(.http, "robots not found", .{ .url = ctx.robots_url });
|
||||||
try ctx.req.robots.putAbsent(ctx.robots_url);
|
try ctx.req.robots.putAbsent(ctx.robots_url);
|
||||||
}
|
}
|
||||||
@@ -368,9 +369,7 @@ fn robotsDoneCallback(ctx_ptr: *anyopaque) !void {
|
|||||||
|
|
||||||
fn robotsErrorCallback(ctx_ptr: *anyopaque, err: anyerror) void {
|
fn robotsErrorCallback(ctx_ptr: *anyopaque, err: anyerror) void {
|
||||||
const ctx: *RobotsRequestContext = @ptrCast(@alignCast(ctx_ptr));
|
const ctx: *RobotsRequestContext = @ptrCast(@alignCast(ctx_ptr));
|
||||||
defer ctx.client.allocator.destroy(ctx);
|
defer ctx.deinit();
|
||||||
defer ctx.buffer.deinit(ctx.client.allocator);
|
|
||||||
defer ctx.client.allocator.free(ctx.robots_url);
|
|
||||||
|
|
||||||
log.warn(.http, "robots fetch failed", .{ .err = err });
|
log.warn(.http, "robots fetch failed", .{ .err = err });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user