Skip to content

Commit

Permalink
Align client-hints processing with Chromium's implementation
Browse files Browse the repository at this point in the history
This change aligns the processing of Client-Hints with the shipped
Chromium implementation, by changing the following:
* Clone the environment settings object's client-hints set to the request's
  client-hints set.
* Apply CH processing to all requests, rather than only subresource
  requests.
* Add processing of new CH headers, added in #725

It also renames "client-hints list" to "client-hints set", and changes
it to be a set, to match related HTML spec changes.
  • Loading branch information
yoavweiss committed Aug 21, 2018
1 parent e6cbef2 commit ee93d96
Showing 1 changed file with 62 additions and 52 deletions.
114 changes: 62 additions & 52 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,11 @@ to not have to set <a for=/>request</a>'s <a for=request>referrer</a>.


<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-client-hints-list>client hints list</dfn>,
which is a <a lt="client hints list" for=client>client-hints list</a>. Unless stated
otherwise, it is the empty list.
<dfn export for=request id=concept-request-client-hints-list>client-hints set</dfn>,
which is a <a lt="client-hints set">client-hints set</a>. Unless stated
otherwise, it is the empty set.

<p class="note no-backref">This will be used to override a client hints list associated with
<p class="note no-backref">This will be used to override a client-hints set associated with
an <a>environment settings object</a>.
[[!CLIENT-HINTS]]

Expand Down Expand Up @@ -1825,14 +1825,14 @@ run these steps:
</ol>


<h3 id=client-hints-list>Client hints list</h3>
<h3 id=client-hints-list>Client-hints set</h3>

<p class=note>This section will be integrated into HTTP Client Hints.
<p class=XXX>This section will be integrated into HTTP Client-Hints.
[[!CLIENT-HINTS]]
<!-- XXX -->

<p>A <dfn export id=concept-client-hints-list for=client>client hints list</dfn> is a
<a for=/>list</a> of
<p>A <dfn export id=concept-client-hints-list>client-hints set</dfn> is a
<a for=/>set</a> of
<a href=http://httpwg.org/http-extensions/client-hints.html#accept-ch>Client hint tokens</a>, each
of which is one of `<code>DPR</code>`, `<code>Save-Data</code>`, `<code>Viewport-Width</code>`, or
`<code>Width</code>`.
Expand Down Expand Up @@ -2640,6 +2640,10 @@ the request.
<a for=request>origin</a> to <var>request</var>'s
<a for=request>client</a>'s <a for="environment settings object">origin</a>.

<li><p>Set <var>request</var>'s <a for=request>client-hints set</a> to be a <a for=list>clone</a>
of the <a for="environment settings object">client-hints set</a> of the <var>request</var>'s
<a for=request>client</a>'s <a for="environment settings object">global object</a>.

<li>
<p>If <var>request</var>'s <a for=request>header list</a>
<a for="header list">does not contain</a> `<code>Accept</code>`, then:
Expand Down Expand Up @@ -2697,55 +2701,61 @@ the request.
<tbody><tr>
<th><a for=header>Name</a>
<th><a for=header>Value</a>
<tr>
<td>`<code>DPR</code>`
<td>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#dpr>dpr value</a>
<tr>
<td>`<code>Save-Data</code>`
<td>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#save-data>save-data value</a>
<tr>
<td>`<code>Viewport-Width</code>`
<td>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#viewport-width>viewport-width value</a>
</table>

<li>
<p>If <var>request</var> is a <a>subresource request</a>, then:

<ol>
<li>
<p><a for=list>For each</a> <var>hintName</var> of <var>request</var>'s
<a for=client>client hints list</a>:

<ol>
<li>
<p>Let <var>value</var> be the first matching statement, switching on <var>hintName</var>:

<dl class=switch>
<dt>`<code>DPR</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#dpr>dpr value</a>
<dt>`<code>Save-Data</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#save-data>save-data value</a>
<dt>`<code>Viewport-Width</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#viewport-width>viewport-width value</a>
<dt>`<code>Width</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#width>width value</a>
</dl>

<li><p>A user agent should <a for="header list">append</a>
<var>hintName</var>/<var>value</var> to <var>request</var>'s <a for=request>header list</a>.
</ol>

<li><p>Let <var>record</var> be a new
<a for="fetch group">fetch record</a> consisting of
<var>request</var> and this instance of the
<a for=/>fetch</a> algorithm.

<li><p>Append <var>record</var> to <var>request</var>'s
<a for=request>client</a>'s
<a for=fetch>fetch group</a> list of
<a for="fetch group">fetch records</a>.
</ol>
</ol>
<li>

<p><a for=list>For each</a> <var>hintName</var> of <var>request</var>'s
<a for=client>client-hints set</a>:

<ol>
<li>
<p>Let <var>value</var> be the first matching statement, switching on <var>hintName</var>:

<dl class=switch>
<dt>`<code>DPR</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#dpr>dpr value</a>
<dt>`<code>Save-Data</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#save-data>save-data value</a>
<dt>`<code>Viewport-Width</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#viewport-width>viewport-width value</a>
<dt>`<code>Width</code>`
<dd>a suitable <a href=http://httpwg.org/http-extensions/client-hints.html#width>width value</a>
<dt>`<code>Device-Memory</code>`
<dd>a suitable <a href=https://w3c.github.io/device-memory/#sec-device-memory-client-hint-header>Device-Memory value</a>
<dt>`<code>RTT</code>`
<dd>a suitable <a href=https://wicg.github.io/netinfo/#rtt-request-header-field>RTT value</a>
<dt>`<code>Downlink</code>`
<dd>a suitable <a href=https://wicg.github.io/netinfo/#downlink-request-header-field>Downlink value</a>
<dt>`<code>ECT</code>`
<dd>a suitable <a href=https://wicg.github.io/netinfo/#ect-request-header-field>ECT value</a>
</dl>

<li><p>If <var>request</var>'s <a for=request>header list</a> <a for="header list">does not
contain</a> <var>hintName</var>, a user agent should <a for="header list">append</a>
<var>hintName</var>/<var>value</var> to <var>request</var>'s <a for=request>header list</a>.
</ol>

<p class=XXX>The above step should be applicable only for same-origin requests. See
<a href="https://github.com/whatwg/fetch/issues/800">issue</a> for more details.</p>


<li><p>If <var>request</var> is a <a>subresource request</a>, then:
<ol>
<li><p>Let <var>record</var> be a new
<a for="fetch group">fetch record</a> consisting of
<var>request</var> and this instance of the
<a for=/>fetch</a> algorithm.

<li><p>Append <var>record</var> to <var>request</var>'s
<a for=request>client</a>'s
<a for=fetch>fetch group</a> list of
<a for="fetch group">fetch records</a>.
</ol>
</ol>

<li>
<p><a>If aborted</a>, then:
Expand Down

0 comments on commit ee93d96

Please sign in to comment.