Copy of w3c/ServiceWorker#452 (comment)
In the following plans, fetch()
is omitted since fetch(req)
runs new Request(req)
, and therefore it's sufficient to discuss only new Request(req)
.
Request
- a
Request
has a booleanused flag
which is initially set to false req.bodyUsed
=used flag
unavailable
= (req.body
is locked) || (used flag
is set)- The following operations fail when
unavailable
is true. Otherwise, they setused flag
to true, acquire the lock ofreq.body
and release it when done (req.body
becomes"closed"
when done).req.arrayBuffer()
req.blob()
req.formData()
req.json()
req.text()
new Request(req)
cache.put(req, res)
req.clone()
fail whenunavailable
is set.
Response
- a
Response
has a booleanused flag
which is initially set to false res.bodyUsed
=used flag
unavailable
= (res.body
is locked) || (used flag
is set)- The following operations fail when
unavailable
is true. Otherwise, they setused flag
to true, acquire the lock ofres.body
and release it when done.res.arrayBuffer()
res.blob()
res.formData()
res.json()
res.text()
e.respondWith(res)
cache.put(req, res)
res.clone()
fail whenunavailable
is set.
Request
- a
Request
has a booleanbody passed flag
req.bodyUsed
= (req.body
is locked) ||req
'sbody passed flag
is set- The following operations fail when
req.bodyUsed
is set. Otherwise, they acquire the lock ofreq.body
and release it when done.req.arrayBuffer()
req.blob()
req.formData()
req.json()
req.text()
req.clone()
fail whenreq.bodyUsed
is set.- The following operations fail when
req.bodyUsed
is set. Otherwise, they setreq
'sbody passed flag
, acquire the lock ofreq.body
and release it when done (req.body
becomes"closed"
when done).new Request(req)
cache.put(req, res)
Response
- a
Response
has a booleanbody passed flag
res.bodyUsed
= (res.body
is locked) ||res
'sbody passed flag
is set- The following operations fail when
res.bodyUsed
is set. Otherwise, they acquire the lock ofres.body
and release it when done.res.arrayBuffer()
res.blob()
res.formData()
res.json()
res.text()
res.clone()
fail whenres.bodyUsed
is set.- The following operations fail when
res.bodyUsed
is set. Otherwise, they setres
'sbody passed flag
, acquire the lock ofres.body
and release it when done (res.body
becomes"closed"
when done).e.respondWith(res)
cache.put(req, res)
Note
- a
Response
/Request
withbody passed flag
is unset but.body
"errored"
is considered to be one whose headers were received successfully but body wasn't - a
Response
/Request
withbody passed flag
set is considered to be invalid
Same as (A) but the following operations set body passed flag
, confiscate the underlying source and queue from res.body
and error it.
new Request(req)
cache.put(req, res)
e.respondWith(res)
cache.put(req, res)
Same as (A) but the following operations set body passed flag
, confiscate the underlying source and queue from res.body
and close it.
new Request(req)
cache.put(req, res)
e.respondWith(res)
cache.put(req, res)
Request
req.bodyUsed
=req.body
is locked- The following operations fail when
req.body
is locked. Otherwise, they acquire the lock ofreq.body
and release it when done.req.arrayBuffer()
req.blob()
req.formData()
req.json()
req.text()
req.clone()
fails whenreq.body
is locked.- The following operations fail when
req.body
is locked. Otherwise, they acquire the lock ofreq.body
and never release it.new Request(req)
cache.put(req, res)
Response
res.bodyUsed
=res.body
is locked- The following operations fail when
res.body
is locked. Otherwise, they acquire the lock ofres.body
and release it when done.res.arrayBuffer()
res.blob()
res.formData()
res.json()
res.text()
res.clone()
fails whenres.body
is locked.- The following operations fail when
res.body
is locked. Otherwise, they acquire the lock ofres.body
and never release it.e.respondWith(res)
cache.put(req, res)
Note
- Needs change on the Streams API spec to hold the lock of a stream even after draining it.
Request
req.bodyUsed
=req.body
is locked- The following operations fail when
req.body
is locked. Otherwise, they acquire the lock ofreq.body
and release it when done.req.arrayBuffer()
req.blob()
req.formData()
req.json()
req.text()
new Request(req)
cache.put(req, res)
req.clone()
fails whenreq.body
is locked.
Response
res.bodyUsed
=res.body
is locked- The following operations fail when
res.body
is locked. Otherwise, they acquire the lock ofres.body
and release it when done.res.arrayBuffer()
res.blob()
res.formData()
res.json()
res.text()
e.respondWith(res)
cache.put(req, res)
res.clone()
fails whenres.body
is locked.