Skip to content

Lightpanda: the headless browser designed for AI and automation

better handling of stale entry

Muki Kiboigo2fd9e5231bf3
diff --git a/src/network/layer/CacheLayer.zig b/src/network/layer/CacheLayer.zig
index 108d1dce9..308a429aa 100644
--- a/src/network/layer/CacheLayer.zig
+++ b/src/network/layer/CacheLayer.zig
@@ -213,12 +213,6 @@ const CacheContext = struct {
fn headerCallback(response: Response) anyerror!bool {
const self: *CacheContext = @ptrCast(@alignCast(response.ctx));
- defer {
- if (self.stale_entry) |stale| {
- stale.data.deinit();
- }
- self.stale_entry = null;
- }
// For non-transfer responses (fulfilled by interception, or future
// cached-while-cached cases), there's nothing to inspect for caching
@@ -251,6 +245,11 @@ const CacheContext = struct {
return false;
}
+ if (self.stale_entry) |stale| {
+ stale.data.deinit();
+ self.stale_entry = null;
+ }
+
const vary = if (conn.getResponseHeader("vary", 0)) |h| h.value else null;
const maybe_cm = try Cache.tryCache(
arena,