diff --git a/lib/cache/cache.js b/lib/cache/cache.js index 9b3110860cd..9fe24b742ad 100644 --- a/lib/cache/cache.js +++ b/lib/cache/cache.js @@ -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/package.json b/package.json index 3d5f7ed20c5..32af945e17c 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "test:tdd:node-test": "borp -p \"test/node-test/**/*.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", 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." ] } }