Skip to content

Commit

Permalink
cacheStorage: fix bugs make wpts pass (#2596)
Browse files Browse the repository at this point in the history
* cacheStorage: fix bugs make wpts pass

* fixup

* fixup

* caseSensitive
  • Loading branch information
KhafraDev committed Jan 7, 2024
1 parent 77333e7 commit 62278d5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
20 changes: 13 additions & 7 deletions lib/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -146,16 +144,24 @@ class Cache {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' })

requests = webidl.converters['sequence<RequestInfo>'](requests)

// 1.
const responsePromises = []

// 2.
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
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 36 additions & 0 deletions test/wpt/server/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion test/wpt/status/service-workers/cache-storage.status.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
}
}
Expand Down

0 comments on commit 62278d5

Please sign in to comment.