Skip to content

Lightpanda: the headless browser designed for AI and automation

fix max-age tracking on no-cache directive

Muki Kiboigo83a690cdf946
diff --git a/src/network/cache/Cache.zig b/src/network/cache/Cache.zig
index 0890c5a78..77e62393c 100644
--- a/src/network/cache/Cache.zig
+++ b/src/network/cache/Cache.zig
@@ -89,6 +89,11 @@ pub const CacheControl = struct {
return null;
}
if (std.mem.eql(u8, directive, "no-cache")) {
+ if (!max_age_set) {
+ cc.max_age = 0;
+ max_age_set = true;
+ }
+
cc.must_revalidate = true;
continue;
}
@@ -113,7 +118,7 @@ pub const CacheControl = struct {
}
if (!max_age_set) return null;
- if (cc.max_age == 0) return null;
+ if (cc.max_age == 0 and !cc.must_revalidate) return null;
return cc;
}
@@ -282,7 +287,10 @@ test "Cache: CacheControl.parse" {
try testing.expectEqual(600, CacheControl.parse("s-maxage=600, max-age=300").?.max_age);
try testing.expectEqual(null, CacheControl.parse("no-store"));
- try testing.expectEqual(null, CacheControl.parse("no-cache"));
+ try testing.expectEqual(
+ CacheControl{ .max_age = 0, .must_revalidate = true },
+ CacheControl.parse("no-cache"),
+ );
try testing.expectEqual(null, CacheControl.parse("private"));
try testing.expectEqual(null, CacheControl.parse("max-age=300, no-store"));
try testing.expectEqual(