Re: [w3c/ServiceWorker] (WIP) Navigation preload (#983)

jakearchibald commented on this pull request.



>          text: basic filtered response; url: concept-filtered-response-basic
         text: cancel a ReadableStream; url: concept-cancel-readablestream
+        text: cloning the request; url: concept-request-clone

I get the feeling this is the wrong way to do this, but I'm not sure what the right way is

> @@ -3608,6 +3732,29 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
           <li>Set <var>registration</var> to the result of running <a href="#scope-match-algorithm">Match Service Worker Registration</a> algorithm passing <var>request</var>'s <a for="request">url</a> as the argument.</li>
           <li>If <var>registration</var> is null or <var>registration</var>'s <a href="#dfn-active-worker">active worker</a> is null, return null.</li>
           <li>Set <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active worker</a> to <var>registration</var>'s <a href="#dfn-active-worker">active worker</a>.</li>
+          <li>If <var>request</var> is a <a>navigation request</a> and <var>registration</var>'s <a>navigation preload enabled flag</a> is set, and <var>request</var>'s <a>method</a> is `<code>GET</code>`, then:
+            <ol>
+              <li>Let <var>preloadRequest</var> be the result of <a>cloning the request</a> <var>request</var></li>
+              <li>Let <var>preloadRequestHeaders</var> be <var>preloadRequest</var>'s <a>header list</a></li>
+              <li>Let <var>preloadResponseObject</var> be a new {{Response}}object and a new associated {{Headers}} object whose <a>guard</a> is "<code>immutable</code>"</li>
+              <li><a>Append to header list</a> <var>preloadRequestHeaders</var> a new <a>header</a> whose <a>name</a> is `<code>Service-Worker-Navigation-Preload</code>` and <a>value</a> is <var>registration</var>'s <a>navigation preload header value</a></li>
+              <li>Set <var>preloadRequest</var>'s <a>skip-service-worker flag</a></li>
+              <li>Set <var>navigationPreload</var> to a new <a>promise</a>.</li>
+              <li>Run the following substeps <a>in parallel</a>:
+                <ol>
+                  <li>
+                    <p><a>Fetch</a> <var>preloadRequest</var>.</p>
+                    <p>To <a>process response</a> for <var>preloadResponse</var>, run these substeps:</p>
+                    <ol>
+                      <li><p>If <var>preloadResponse</var>'s <a>type</a> is "<code>error</code>", reject <var>navigationPreload</var> with a <code>TypeError</code> and terminate these substeps.</li>

`type` isn't linking up properly, but I'm not sure what the right way to do this is.

> @@ -3608,6 +3732,29 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
           <li>Set <var>registration</var> to the result of running <a href="#scope-match-algorithm">Match Service Worker Registration</a> algorithm passing <var>request</var>'s <a for="request">url</a> as the argument.</li>
           <li>If <var>registration</var> is null or <var>registration</var>'s <a href="#dfn-active-worker">active worker</a> is null, return null.</li>
           <li>Set <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active worker</a> to <var>registration</var>'s <a href="#dfn-active-worker">active worker</a>.</li>
+          <li>If <var>request</var> is a <a>navigation request</a> and <var>registration</var>'s <a>navigation preload enabled flag</a> is set, and <var>request</var>'s <a>method</a> is `<code>GET</code>`, then:

@annevk this is the section I'm least confident in - it's fetch for the preload. I don't think redirects are a problem since the mode will be `manual`. When the redirect is sent back to the navigate algorithm it'll be associated with the *original* request, which won't have the header.

Having said that, that may be unexpected for same-origin redirects.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/pull/983#pullrequestreview-2947819

Received on Wednesday, 5 October 2016 16:17:38 UTC