Skip to content

Commit

Permalink
Fix cache logic
Browse files Browse the repository at this point in the history
As written, the cache is append only. This is incorrect as, with any
Accept-CH header set, the entire cache should be overwritten with the
new contents.

#134 (comment)
  • Loading branch information
arichiv committed Dec 16, 2022
1 parent 5f8052b commit 5671988
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ header in a response. This sets the origin's [=/client hints set=] to an empty s

Note: As the cache can only be modified by the top-level frame, it is considered to be partitioned.

To <dfn>add a new Accept-CH cache entry</dfn> to the [=Accept-CH cache=],
given an [=accept-ch-cache/origin=] |origin| and a [=/client hints set=] |hintSet|,
[=map/set=] [=Accept-CH cache=][|origin|] to |hintSet|.

When asked to <dfn>retrieve the client hints set</dfn> given a |settingsObject|:
When asked to <dfn>retrieve the Client Hints set</dfn> given a |settingsObject|:

<ol>
<li>Let |hintSet| be an empty [=ordered set=].
Expand All @@ -145,16 +141,20 @@ When asked to <dfn>retrieve the client hints set</dfn> given a |settingsObject|:
<li>For each |hint| in |hintSet|, [=set/append=] |hint| to |settingsObject|'s [=environment settings object/client hints set=].
</ol>

When asked to <dfn abstract-op>update the Client Hints set</dfn> given a |settingsObject| and |response|:
When asked to <dfn abstract-op>create or override the Client Hints set</dfn> given a |settingsObject| and |response|:

<ol>
<li>Run [=retrieve the client hints set=] with |settingsObject|.
<li>If |settingsObject| is a [=non-secure context=], abort these steps.
<li>Let |browsingContext| be |settingsObject|'s [=environment settings object/global object=]'s [=Window/browsing context=].
<li>If the [=top-level browsing context=] does not equal |browsingContext|, abort these steps.
<li>If |response|'s `Accept-CH` header is present, parse the header field value according to the
`Accept-CH` header parsing rules, as a [=field-name=]. Add each parsed [=client hints token=] to |settingsObject|'s [=environment settings object/client hints set=].
<li>[=Add a new Accept-CH cache entry=] with |response|'s [=url/origin=] and |settingsObject|'s [=environment settings object/client hints set=].
<li>If |response|'s `Accept-CH` header is not present, abort these steps.
<li>Let |hintSet| be an empty [=ordered set=].
<li>For each |hint| in the result of parsing `Accept-CH` according to the header parsing rules, as a [=field-name=]:
<ol>
<li>If |hint| is a [=client hints token=] add it to |hintSet|.
</ol>
<li>Let |origin| be |response|'s [=url/origin=].
<li>[=map/set=] [=Accept-CH cache=][|origin|] to |hintSet|.
</ol>

<dfn>Delegate-CH</dfn> {#delegate-ch-algo}
Expand Down Expand Up @@ -197,7 +197,7 @@ This specification integrates with the [[!HTML]] specification by patching the a
Navigation response {#navigation-response}
----------

At [=populating a session history entry=], in step 6 after substep 7 call [$update the Client Hints set$] with the [=relevant settings object=] and |response| as inputs.
At [=populating a session history entry=], in step 6 after substep 7 call [$create or override the Client Hints set$] with the [=relevant settings object=] and |response| as inputs.

Service Worker initialization {#service-worker-init}
-----------
Expand Down Expand Up @@ -227,7 +227,7 @@ following steps:
<ol>
<li>If |request| is a [=non-subresource request=] for a "sharedworker" or "worker" [=request/destination=], exit without appending any hints to the [=request/header list=].
<li>Let |hintSet| be an empty [=/client hints set=].
<li>Run [=retrieve the client hints set=] with |settingsObject|.
<li>Run [=retrieve the Client Hints set=] with |settingsObject|.
<li>For each [=client hints token=] |lowEntropyHint| in the registry's [=low entropy hint table=], [=set/append=] |lowEntropyHint| to |hintSet|.
<li>If |request|'s [=request/client=] is not null, then for each [=client hints token=] |requestHint| in
|settingsObject|'s [=environment settings object/client hints set=], [=set/append=] |requestHint| to
Expand Down

0 comments on commit 5671988

Please sign in to comment.