From 3bd414384dc75b7fe59b6a5826a58e9beb2e5295 Mon Sep 17 00:00:00 2001 From: Khafra Date: Sat, 6 Jan 2024 21:17:03 -0500 Subject: [PATCH 1/4] cacheStorage: fix bugs make wpts pass --- lib/cache/cache.js | 22 +++++++----- test/wpt/server/server.mjs | 36 +++++++++++++++++++ .../service-workers/cache-storage.status.json | 3 +- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/lib/cache/cache.js b/lib/cache/cache.js index 9b3110860cd..617bfdaa0c2 100644 --- a/lib/cache/cache.js +++ b/lib/cache/cache.js @@ -55,7 +55,7 @@ class Cache { return } - return p[0] + return p[0].clone() } async matchAll (request = undefined, options = {}) { @@ -112,14 +112,12 @@ class Cache { // 5.5.2 for (const response of responses) { // 5.5.2.1 - const responseObject = new Response(response.body?.source ?? null) - const body = responseObject[kState].body + const responseObject = new Response(null) responseObject[kState] = response - responseObject[kState].body = body responseObject[kHeaders][kHeadersList] = response.headersList responseObject[kHeaders][kGuard] = 'immutable' - responseList.push(responseObject) + responseList.push(responseObject.clone()) } // 6. @@ -146,8 +144,6 @@ class Cache { webidl.brandCheck(this, Cache) webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' }) - requests = webidl.converters['sequence'](requests) - // 1. const responsePromises = [] @@ -155,7 +151,17 @@ class Cache { const requestList = [] // 3. - for (const request of requests) { + for (let request of requests) { + if (request === undefined) { + throw webidl.errors.conversionFailed({ + prefix: 'Cache.addAll', + argument: 'Argument 1', + types: ['undefined is not allowed'] + }) + } + + request = webidl.converters.RequestInfo(request) + if (typeof request === 'string') { continue } diff --git a/test/wpt/server/server.mjs b/test/wpt/server/server.mjs index d12b4936978..9a8bad4b83a 100644 --- a/test/wpt/server/server.mjs +++ b/test/wpt/server/server.mjs @@ -370,6 +370,42 @@ const server = createServer(async (req, res) => { res.end() return } + case '/service-workers/cache-storage/this-resource-should-not-exist': + case '/service-workers/cache-storage/this-does-not-exist-please-dont-create-it': { + res.statusCode = 404 + res.end() + return + } + case '/service-workers/cache-storage/resources/vary.py': { + if (fullUrl.searchParams.has('clear-vary-value-override-cookie')) { + res.setHeader('cookie', '') + res.end('vary cookie cleared') + return + } + + const setCookieVary = fullUrl.searchParams.get('set-vary-value-override-cookie') ?? '' + + if (setCookieVary) { + res.setHeader('set-cookie', `vary-value-override=${setCookieVary}`) + res.end('vary cookie set') + return + } + + const cookieVary = req.headers.cookie?.split(';').find((c) => c.includes('vary-value-override=')) + + if (cookieVary) { + res.setHeader('vary', `${cookieVary}`) + } else { + const queryVary = fullUrl.searchParams.get('vary') + + if (queryVary) { + res.setHeader('vary', queryVary) + } + } + + res.end('vary response') + return + } default: { res.statusCode = 200 res.end(fullUrl.toString()) diff --git a/test/wpt/status/service-workers/cache-storage.status.json b/test/wpt/status/service-workers/cache-storage.status.json index 09a291e4dbb..e61e8b73e9b 100644 --- a/test/wpt/status/service-workers/cache-storage.status.json +++ b/test/wpt/status/service-workers/cache-storage.status.json @@ -17,7 +17,8 @@ "cache-match.https.any.js": { "note": "requires https server", "fail": [ - "cors-exposed header should be stored correctly." + "cors-exposed header should be stored correctly.", + "Cache.match ignores vary headers on opaque response." ] } } From 45239d8423195826ecd97ff4bed2966595373820 Mon Sep 17 00:00:00 2001 From: Khafra Date: Sat, 6 Jan 2024 21:19:41 -0500 Subject: [PATCH 2/4] fixup --- lib/cache/cache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cache/cache.js b/lib/cache/cache.js index 617bfdaa0c2..9fe24b742ad 100644 --- a/lib/cache/cache.js +++ b/lib/cache/cache.js @@ -55,7 +55,7 @@ class Cache { return } - return p[0].clone() + return p[0] } async matchAll (request = undefined, options = {}) { From 7982e28de76b9a1425ccd87ce925c05a4cd93a8b Mon Sep 17 00:00:00 2001 From: Khafra Date: Sat, 6 Jan 2024 21:26:55 -0500 Subject: [PATCH 3/4] fixup --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 17015f7b1b8..0e25274a566 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w", "test:typescript": "tsd && tsc --skipLibCheck test/imports/undici-import.ts", "test:websocket": "borp --coverage -p \"test/websocket/*.js\"", - "test:wpt": "node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node test/wpt/start-websockets.mjs", + "test:wpt": "node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node test/wpt/start-websockets.mjs && node test/wpt/start-cachestorage.mjs", "coverage": "nyc --reporter=text --reporter=html npm run test", "coverage:ci": "nyc --reporter=lcov npm run test", "bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run", From efef2fbdd63241e68859ceb22c6298a0b9789e1a Mon Sep 17 00:00:00 2001 From: Khafra Date: Sat, 6 Jan 2024 21:31:32 -0500 Subject: [PATCH 4/4] caseSensitive --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e25274a566..ffa2608650e 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w", "test:typescript": "tsd && tsc --skipLibCheck test/imports/undici-import.ts", "test:websocket": "borp --coverage -p \"test/websocket/*.js\"", - "test:wpt": "node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node test/wpt/start-websockets.mjs && node test/wpt/start-cachestorage.mjs", + "test:wpt": "node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node test/wpt/start-websockets.mjs && node test/wpt/start-cacheStorage.mjs", "coverage": "nyc --reporter=text --reporter=html npm run test", "coverage:ci": "nyc --reporter=lcov npm run test", "bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run",