Lightpanda: the headless browser designed for AI and automation
webapi: Cache mutable response headers
Karl Seguina5aedfd288c7
diff --git a/src/browser/tests/cache/cache.html b/src/browser/tests/cache/cache.htmlindex 654a141a7..0db8aab6e 100644--- a/src/browser/tests/cache/cache.html+++ b/src/browser/tests/cache/cache.html@@ -1,4 +1,5 @@<!DOCTYPE html>+<meta name=lp-mode content=test><script src="../testing.js"></script><script id=cache_storage type=module>@@ -33,7 +34,7 @@testing.expectEqual(true, after);// creation ordertesting.expectTrue(names.indexOf('cs-a') >= 0);- testing.expectEqual(names.indexOf('cs-a') + 1, names.indexOf('cs-b'));+ testing.expectEqual(true, names.indexOf('cs-a') < names.indexOf('cs-b'));testing.expectEqual(true, deleted);testing.expectEqual(false, deleted_again);testing.expectEqual(false, gone);@@ -72,12 +73,7 @@const replaced = await (await cache.match('/a?x=1')).text();const keys = await cache.keys();- let immutable = null;- try {- hit.headers.set('x-custom', 'nope');- } catch (e) {- immutable = e;- }+ hit.headers.set('x-custom', 'nope');state.resolve();await state.done(() => {@@ -89,8 +85,7 @@testing.expectEqual(201, hit.status);testing.expectEqual('Created', hit.statusText);testing.expectEqual('text/x-test', hit.headers.get('content-type'));- testing.expectEqual('abc', hit.headers.get('x-custom'));- testing.expectTrue(immutable instanceof TypeError);+ testing.expectEqual('nope', hit.headers.get('x-custom'));testing.expectEqual('hello', hit_text);testing.expectTrue(hit !== hit2);testing.expectEqual('hello', hit2_text);diff --git a/src/browser/tests/cache/disabled.html b/src/browser/tests/cache/disabled.htmlindex a48b6d8ad..b8a530692 100644--- a/src/browser/tests/cache/disabled.html+++ b/src/browser/tests/cache/disabled.html@@ -1,4 +1,5 @@<!DOCTYPE html>+<meta name=lp-mode content=test><script src="../testing.js"></script><script id="caches_absent_without_the_flag">@@ -6,8 +7,10 @@// navigator.serviceWorker it is absent rather than null, and only the way in// is removed.{- testing.expectFalse('caches' in window);- testing.expectEqual(undefined, window.caches);+ testing.diverges("Chrome has this enabled", () => {+ testing.expectFalse('caches' in window);+ testing.expectEqual(undefined, window.caches);+ });testing.expectTrue(typeof CacheStorage === 'function');testing.expectTrue(typeof Cache === 'function');}@@ -23,7 +26,9 @@state.resolve();await state.done(() => {- testing.expectEqual(false, data.present);+ testing.diverges("Chrome has this enabled", () => {+ testing.expectEqual(false, data.present);+ });testing.expectEqual('function', data.constructor);});}diff --git a/src/browser/webapi/cache/Cache.zig b/src/browser/webapi/cache/Cache.zigindex dbb0a1c27..83a01b83c 100644--- a/src/browser/webapi/cache/Cache.zig+++ b/src/browser/webapi/cache/Cache.zig@@ -350,7 +350,10 @@ fn toResponse(entry: *const Store.Entry, exec: *const Execution) !*Response {._body = .{ .bytes = try arena.dupe(u8, entry.body) },._type = entry.response_type,._is_redirected = entry.is_redirected,- ._headers = try .initGuarded(.{ .strings = entry.headers }, .immutable, exec),+ // pretty sure, by the spec, this should be .immutable, but both Firefox+ // and Chrome allow mutation to the header, and I found no WPT tests that+ // checks either way.+ ._headers = try .initGuarded(.{ .strings = entry.headers }, .response, exec),};arena.report();return response;