Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cacheStorage: fix bugs make wpts pass #2596

Merged
merged 4 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird: this whole thing i'm kinda iffy about, somehow this was setting a 0-length uint8array as the source and was locking the stream.

Copy link
Member Author

@KhafraDev KhafraDev Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cloning itself makes sense, if you matched a Response and then consumed its body, the cached stream would be locked if you matched it again. I'm referring to the chunk above it, which github cut off.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the body assigned to the new response?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      responseObject[kState] = response

response here is actually an internal response, not a Response object. It contains the body.

}

// 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)
Copy link
Member Author

@KhafraDev KhafraDev Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird: any value is technically allowed in RequestInfo (it gets stringified and then parsed as a URL with the window's location typically), but undefined is very explicitly not allowed here for some reason.


// 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
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
Loading