Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process 103 Early Hints response #1404

Merged
merged 12 commits into from Apr 7, 2022
69 changes: 51 additions & 18 deletions fetch.bs
Expand Up @@ -199,6 +199,7 @@ lt="authentication entry">authentication entries</a> (for HTTP authentication).
<dt><dfn for="fetch params" id=fetch-params-process-request-body>process request body chunk length</dfn>
(default null)
<dt><dfn for="fetch params">process request end-of-body</dfn> (default null)
<dt><dfn for="fetch params">process early hints response</dfn> (default null)
<dt><dfn for="fetch params">process response</dfn> (default null)
<dt><dfn for="fetch params">process response end-of-body</dfn> (default null)
<dt><dfn for="fetch params">process response consume body</dfn> (default null)
Expand Down Expand Up @@ -1099,7 +1100,7 @@ format of range header value can be set using <a>add a range header</a>.
<p class=XXX>Various edge cases in mapping HTTP/1's <code>status-code</code> to this concept are
worked on in <a href=https://github.com/whatwg/fetch/issues/1156>issue #1156</a>.

<p>A <dfn export>null body status</dfn> is a <a for=/>status</a> that is 101, 204, 205, or 304.
<p>A <dfn export>null body status</dfn> is a <a for=/>status</a> that is 101, 103, 204, 205, or 304.

<p>An <dfn export>ok status</dfn> is a <a for=/>status</a> in the range 200 to 299, inclusive.

Expand Down Expand Up @@ -3744,15 +3745,16 @@ optional algorithm
<dfn export for=fetch id=process-request-body><var>processRequestBodyChunkLength</var></dfn>, an
optional algorithm
<dfn export for=fetch id=process-request-end-of-body oldids=process-request-end-of-file><var>processRequestEndOfBody</var></dfn>,
an optional algorithm <dfn export for=fetch id=process-response><var>processResponse</var></dfn>, an
optional algorithm <dfn export for=fetch><var>processResponseEndOfBody</var></dfn>, an optional
algorithm
an optional algorithm <dfn export for=fetch><var>processEarlyHintsResponse</var></dfn>, an optional
algorithm <dfn export for=fetch id=process-response><var>processResponse</var></dfn>, an optional
algorithm <dfn export for=fetch><var>processResponseEndOfBody</var></dfn>, an optional algorithm
<dfn export for=fetch id=process-response-end-of-body oldids=process-response-end-of-file><var>processResponseConsumeBody</var></dfn>,
and an optional boolean <dfn export for=fetch><var>useParallelQueue</var></dfn> (default false), run
the steps below. If given, <var>processRequestBodyChunkLength</var> must be an algorithm accepting
an integer representing the number of bytes transmitted. If given,
<var>processRequestEndOfBody</var> must be an algorithm accepting no arguments. If given,
<var>processResponse</var> must be an algorithm accepting a <a for=/>response</a>. If given,
<var>processEarlyHintsResponse</var> must be an algorithm accepting a <a for=/>response</a>. If
given, <var>processResponse</var> must be an algorithm accepting a <a for=/>response</a>. If given,
<var>processResponseEndOfBody</var> must be an algorithm accepting a <a for=/>response</a>. If
given, <var>processResponseConsumeBody</var> must be an algorithm accepting a <a for=/>response</a>
and null, failure, or a <a for=/>byte sequence</a>.
Expand Down Expand Up @@ -3809,6 +3811,7 @@ the request.
<a for="fetch params">process request body chunk length</a> is
<var>processRequestBodyChunkLength</var>,
<a for="fetch params">process request end-of-body</a> is <var>processRequestEndOfBody</var>,
<a for="fetch params">process early hints response</a> is <var>processEarlyHintsResponse</var>,
<a for="fetch params">process response</a> is <var>processResponse</var>,
<a for="fetch params">process response consume body</a> is <var>processResponseConsumeBody</var>,
<a for="fetch params">process response end-of-body</a> is <var>processResponseEndOfBody</var>,
Expand Down Expand Up @@ -5460,22 +5463,52 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<a for=request>body</a> cannot be recreated and that is why the buffer is needed.
</div>

<li><p>Set <var>timingInfo</var>'s
<a for="fetch timing info">final network-response start time</a> to the
<a for=/>coarsened shared current time</a> given <var>fetchParams</var>'s
<a for="fetch params">cross-origin isolated capability</a>, immediately after the user agent's
HTTP parser receives the first byte of the response (e.g., frame header bytes for HTTP/2 or
response status line for HTTP/1.x).
<li>
<p>While true:

<li><p>Wait until all the <a for=/>headers</a> are transmitted.
<ol>
<li><p>If <var>timingInfo</var>'s
<a for="fetch timing info">final network-response start time</a> is 0, then set
<var>timingInfo</var>'s <a for="fetch timing info">final network-response start time</a> to
<a for=/>coarsened shared current time</a> given <var>fetchParams</var>'s
<a for="fetch params">cross-origin isolated capability</a>, immediately after the user
agent's HTTP parser receives the first byte of the response (e.g., frame header bytes for
HTTP/2 or response status line for HTTP/1.x).

<li>
<p>Any <a for=/>responses</a> whose <a for=response>status</a> is in the range 100 to 199,
inclusive, and is not 101, are to be ignored, except for the purposes of setting
<var>timingInfo</var>'s <a for="fetch timing info">final network-response start time</a> above.
<li><p>Wait until all the HTTP response headers are transmitted.

<li><p>Let <var>status</var> be the HTTP response's status code.

<li>
<p>If <var>status</var> is in the range 100 to 199, inclusive:

<ol>
<li><p>If <var>status</var> is 101, <a for=iteration>break</a>.

<li>
<p>If <var>status</var> is 103 and <var>fetchParams</var>'s
<a for="fetch params">process early hints response</a> is non-null, then:

<ol>
<li>
<p><a for=/>Assert</a>: <var>request</var>'s <a for=request>mode</a> is
"<code>navigate</code>".

<p class=note>Processing of early hints is only vetted for navigations.
Copy link
Member

@annevk annevk Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most significant change I made. I made it because the earlier assertion focused on "cors" while "same-origin" also exists and wasn't addressed. And it's also not clear to me that "cors" couldn't be made to work if we wanted it to work.

If this and my other changes look okay (please an explicit comment if you had a look) I think this can land after all the other requirements are met and the HTML PR is also ready to land.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for review and edit. It looks great to me.

Currently I'm adding WPTs. I'll add another comment in this PR when this could be ready to land.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WPTs are pretty comprehensive!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we now have good test coverage in WPT. It seems that the HTML PR (whatwg/html#7675) is getting ready to land and wants to have cross-links to this change. It would be great to merge this PR.


<li><p><a>Queue a fetch task</a> to run <var>fetchParams</var>'s
<a for="fetch params">process early hints response</a>, with <a for=/>response</a>.
</ol>

<li><p><a for=iteration>Continue</a>.
</ol>

<p class="note no-backref">These kind of <a for=/>responses</a> are eventually followed by a
"final" <a for=/>response</a>.
<p class=note>These kind of HTTP responses are eventually followed by a "final" HTTP
response.

<li><p><a for=iteration>Break</a>.
</ol>
</li>
</ul>

<p class=note>The exact layering between Fetch and HTTP still needs to be sorted through and
Expand Down