Re: [whatwg/fetch] Send `Sec-Purpose: prefetch` header for prefetch requests (PR #1576)

@annevk commented on this pull request.



> @@ -4088,6 +4090,26 @@ run these steps:
 </div>
 
 
+<h3 id="sec-purpose-header">`<code>Sec-Purpose</code>` header</h3>
+
+<p>The `<dfn export http-header id=http-sec-purpose><code>Sec-Purpose</code></dfn>` HTTP request
+header specifies that the request serves one or more purposes other than requesting the resource for
+immediate use by the user.
+
+<p>The `<a http-header><code>Sec-Purpose</code></a>` header field is a <a>structured header</a>
+whose value must be a <a data-lt="structured header list">list</a>. Its ABNF is: [[!RFC8941]]

I think for now we can just state that it has to be a token? Also no need for ABNF.

> @@ -4088,6 +4090,26 @@ run these steps:
 </div>
 
 
+<h3 id="sec-purpose-header">`<code>Sec-Purpose</code>` header</h3>
+
+<p>The `<dfn export http-header id=http-sec-purpose><code>Sec-Purpose</code></dfn>` HTTP request
+header specifies that the request serves one or more purposes other than requesting the resource for
+immediate use by the user.
+
+<p>The `<a http-header><code>Sec-Purpose</code></a>` header field is a <a>structured header</a>
+whose value must be a <a data-lt="structured header list">list</a>. Its ABNF is: [[!RFC8941]]
+
+<pre><code class=lang-abnf>
+Sec-Purpose    = sf-list
+</code></pre>
+
+It may contain an item member which is the token "prefetch". If so, this indicates the request’s

Needs `<code>` as well.

> +immediate use by the user.
+
+<p>The `<a http-header><code>Sec-Purpose</code></a>` header field is a <a>structured header</a>
+whose value must be a <a data-lt="structured header list">list</a>. Its ABNF is: [[!RFC8941]]
+
+<pre><code class=lang-abnf>
+Sec-Purpose    = sf-list
+</code></pre>
+
+It may contain an item member which is the token "prefetch". If so, this indicates the request’s
+purpose is to download a resource it is anticipated will be fetched shortly.
+
+<p class=note>This can be used, for example, to let the server adjust the caching expiry for
+prefetches, to disallow the prefetch by rejecting the request, or treat it differently
+for the purpose of counting page visits.
+

You're eating a newline.

> @@ -5313,6 +5335,10 @@ run these steps:
    <li><p><a abstract-op lt="append the Fetch metadata headers for a request">Append the Fetch metadata headers for <var>httpRequest</var></a>.
    [[!FETCH-METADATA]]
 
+   <li><p>If <var>httpRequest</var>'s <a for=request>initiator</a> is "<code>prefetch</code>", then
+   <a>set a structured field value</a> given (`<a http-header><code>Sec-Purpose</code></a>`,
+   "<code>prefetch</code>") in <var>httpRequest</var>'s <a for=request>header list</a>.

We're hitting a problem here with this API and ambiguity between strings and tokens.

We could omit the quotes, but that's not really a thing we normally define. Perhaps we just write it out as:

> token "`prefetch`"

with an xref for "token"?

@domenic thoughts?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/pull/1576#pullrequestreview-1247470553

You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/pull/1576/review/1247470553@github.com>

Received on Friday, 13 January 2023 11:25:59 UTC