Skip to content

Commit 62278d5

Browse files
authored
cacheStorage: fix bugs make wpts pass (#2596)
* cacheStorage: fix bugs make wpts pass * fixup * fixup * caseSensitive
1 parent 77333e7 commit 62278d5

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

lib/cache/cache.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ class Cache {
112112
// 5.5.2
113113
for (const response of responses) {
114114
// 5.5.2.1
115-
const responseObject = new Response(response.body?.source ?? null)
116-
const body = responseObject[kState].body
115+
const responseObject = new Response(null)
117116
responseObject[kState] = response
118-
responseObject[kState].body = body
119117
responseObject[kHeaders][kHeadersList] = response.headersList
120118
responseObject[kHeaders][kGuard] = 'immutable'
121119

122-
responseList.push(responseObject)
120+
responseList.push(responseObject.clone())
123121
}
124122

125123
// 6.
@@ -146,16 +144,24 @@ class Cache {
146144
webidl.brandCheck(this, Cache)
147145
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' })
148146

149-
requests = webidl.converters['sequence<RequestInfo>'](requests)
150-
151147
// 1.
152148
const responsePromises = []
153149

154150
// 2.
155151
const requestList = []
156152

157153
// 3.
158-
for (const request of requests) {
154+
for (let request of requests) {
155+
if (request === undefined) {
156+
throw webidl.errors.conversionFailed({
157+
prefix: 'Cache.addAll',
158+
argument: 'Argument 1',
159+
types: ['undefined is not allowed']
160+
})
161+
}
162+
163+
request = webidl.converters.RequestInfo(request)
164+
159165
if (typeof request === 'string') {
160166
continue
161167
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"test:tdd:node-test": "borp -p \"test/node-test/**/*.js\" -w",
8787
"test:typescript": "tsd && tsc --skipLibCheck test/imports/undici-import.ts",
8888
"test:websocket": "borp --coverage -p \"test/websocket/*.js\"",
89-
"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",
89+
"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",
9090
"coverage": "nyc --reporter=text --reporter=html npm run test",
9191
"coverage:ci": "nyc --reporter=lcov npm run test",
9292
"bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run",

test/wpt/server/server.mjs

+36
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,42 @@ const server = createServer(async (req, res) => {
370370
res.end()
371371
return
372372
}
373+
case '/service-workers/cache-storage/this-resource-should-not-exist':
374+
case '/service-workers/cache-storage/this-does-not-exist-please-dont-create-it': {
375+
res.statusCode = 404
376+
res.end()
377+
return
378+
}
379+
case '/service-workers/cache-storage/resources/vary.py': {
380+
if (fullUrl.searchParams.has('clear-vary-value-override-cookie')) {
381+
res.setHeader('cookie', '')
382+
res.end('vary cookie cleared')
383+
return
384+
}
385+
386+
const setCookieVary = fullUrl.searchParams.get('set-vary-value-override-cookie') ?? ''
387+
388+
if (setCookieVary) {
389+
res.setHeader('set-cookie', `vary-value-override=${setCookieVary}`)
390+
res.end('vary cookie set')
391+
return
392+
}
393+
394+
const cookieVary = req.headers.cookie?.split(';').find((c) => c.includes('vary-value-override='))
395+
396+
if (cookieVary) {
397+
res.setHeader('vary', `${cookieVary}`)
398+
} else {
399+
const queryVary = fullUrl.searchParams.get('vary')
400+
401+
if (queryVary) {
402+
res.setHeader('vary', queryVary)
403+
}
404+
}
405+
406+
res.end('vary response')
407+
return
408+
}
373409
default: {
374410
res.statusCode = 200
375411
res.end(fullUrl.toString())

test/wpt/status/service-workers/cache-storage.status.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"cache-match.https.any.js": {
1818
"note": "requires https server",
1919
"fail": [
20-
"cors-exposed header should be stored correctly."
20+
"cors-exposed header should be stored correctly.",
21+
"Cache.match ignores vary headers on opaque response."
2122
]
2223
}
2324
}

0 commit comments

Comments
 (0)