Skip to content

Commit 89cfc1d

Browse files
authored
Remove location URL as field on responses
It does not need to be stored on a response and therefore resulted in confusion. Also clarify that synthetic responses need to have an absolute URL in the Location header field value (Response.redirect() does this automatically). Corresponding HTML PR: whatwg/html#6340. Tests: https://chromium-review.googlesource.com/c/chromium/src/+/2665871. Closes #631, closes #633, closes #958, closes #1146, and closes web-platform-tests/wpt#10449. (Some of these can be closed due to #1030 making response's URL no longer null for network responses.)
1 parent 987c3fd commit 89cfc1d

File tree

1 file changed

+46
-42
lines changed

1 file changed

+46
-42
lines changed

fetch.bs

+46-42
Original file line numberDiff line numberDiff line change
@@ -1882,16 +1882,6 @@ allowed on the resource fetched by looking at the flag of the response returned.
18821882
the response of a redirect has to be set if it was set for previous responses in the redirect chain,
18831883
this is also tracked internally using the request's <a for=request>timing allow failed flag</a>.
18841884

1885-
<p>A <a for=/>response</a> can have an associated
1886-
<dfn export for=response id=concept-response-location-url>location URL</dfn> (null, failure, or a
1887-
<a for=/>URL</a>). Unless specified otherwise, <a for=/>response</a> has no
1888-
<a for=response>location URL</a>.
1889-
1890-
<p class="note no-backref">This concept is used for redirect handling in Fetch and in HTML's
1891-
navigate algorithm. It ensures `<code>Location</code>` has
1892-
<a lt="extracting header values">its value extracted</a> consistently and only once.
1893-
[[!HTML]]
1894-
18951885
<hr>
18961886

18971887
<p>A <a for=/>response</a> whose
@@ -2008,6 +1998,36 @@ is a <a>filtered response</a> whose
20081998
<p>A <dfn export id=concept-stale-response>stale response</dfn> is a <a for=/>response</a> that is
20091999
not a <a>fresh response</a> or a <a>stale-while-revalidate response</a>.
20102000

2001+
<hr>
2002+
2003+
<p>The <dfn export for=response id=concept-response-location-url>location URL</dfn> algorithm of
2004+
given a <a for=/>response</a> <var>response</var> is the following steps. They return null, failure,
2005+
or a <a for=/>URL</a>.
2006+
2007+
<ol>
2008+
<li><p>If <var>response</var>'s <a for=response>status</a> is not a <a>redirect status</a>, then
2009+
return null.
2010+
2011+
<li><p>Let <var>location</var> be the result of <a>extracting header list values</a> given
2012+
`<code>Location</code>` and <var>response</var>'s <a for=response>header list</a>.
2013+
<!-- https://github.com/whatwg/fetch/issues/814#issuecomment-431366126 -->
2014+
2015+
<li>
2016+
<p>If <var>location</var> is a <a for=header>value</a>, then set <var>location</var> to the result
2017+
of <a lt="url parser">parsing</a> <var>location</var> with <var>response</var>'s
2018+
<a for=response>URL</a>.
2019+
2020+
<p class=note>If <var>response</var> was constructed through the {{Response}} constructor,
2021+
<var>response</var>'s <a for=response>URL</a> will be null, meaning that <var>location</var> will
2022+
only parse successfully if it is an <a>absolute-URL-with-fragment string</a>.
2023+
2024+
<li><p>Return <var>location</var>.
2025+
</ol>
2026+
2027+
<p class=note>The <a for=response>location URL</a> algorithm is exclusively used for redirect
2028+
handling in this standard and in <cite>HTML</cite>'s navigate algorithm which handles redirects
2029+
manually. [[!HTML]]
2030+
20112031

20122032
<h4 id=miscellaneous>Miscellaneous</h4>
20132033

@@ -3950,16 +3970,6 @@ optional <i>CORS-preflight flag</i>, run these steps:
39503970

39513971
<p class=note>303 is excluded as certain communities ascribe special status to it.
39523972

3953-
<li><p>Let <var>location</var> be the result of <a>extracting header list values</a> given
3954-
`<code>Location</code>` and <var>actualResponse</var>'s <a for=response>header list</a>.
3955-
3956-
<li><p>If <var>location</var> is a <a for=header>value</a>, then set <var>location</var> to the
3957-
result of <a lt="URL parser">parsing</a> <var>location</var> with <var>actualResponse</var>'s
3958-
<a for=response>URL</a>.
3959-
3960-
<li><p>Set <var>actualResponse</var>'s
3961-
<a for=response>location URL</a> to <var>location</var>.
3962-
39633973
<li>
39643974
<p>Switch on <var>request</var>'s
39653975
<a for=request>redirect mode</a>:
@@ -3998,18 +4008,14 @@ optional <i>CORS-preflight flag</i>, run these steps:
39984008
<a>filtered response</a>, and <var>response</var>'s
39994009
<a for="filtered response">internal response</a> otherwise.
40004010

4001-
<li><p>If <var>actualResponse</var>'s <a for=response>location URL</a>
4002-
is null, then return <var>response</var>.
4011+
<li><p>Let <var>locationURL</var> be <var>actualResponse</var>'s <a for=response>location URL</a>.
4012+
4013+
<li><p>If <var>locationURL</var> is null, then return <var>response</var>.
40034014

4004-
<li><p>If <var>actualResponse</var>'s <a for=response>location URL</a>
4005-
is failure, then return a <a>network error</a>.
4006-
<!-- only Gecko does this; and even that is currently more complicated -->
4015+
<li><p>If <var>locationURL</var> is failure, then return a <a>network error</a>.
40074016

4008-
<li><p>If <var>actualResponse</var>'s
4009-
<a for=response>location URL</a>'s
4010-
<a for=url>scheme</a> is <em>not</em> an
4011-
<a>HTTP(S) scheme</a>, then return a
4012-
<a>network error</a>.
4017+
<li><p>If <var>locationURL</var>'s <a for=url>scheme</a> is not an <a>HTTP(S) scheme</a>, then
4018+
return a <a>network error</a>.
40134019

40144020
<li><p>If <var>request</var>'s <a for=request>redirect count</a> is
40154021
twenty, return a <a>network error</a>.
@@ -4018,27 +4024,25 @@ optional <i>CORS-preflight flag</i>, run these steps:
40184024
<a for=request>redirect count</a> by one.
40194025

40204026
<li><p>If <var>request</var>'s <a for=request>mode</a> is "<code>cors</code>",
4021-
<var>actualResponse</var>'s <a for=response>location URL</a>
4022-
<a lt="include credential">includes credentials</a>, and <var>request</var>'s
4023-
<a for=request>origin</a> is not <a>same origin</a> with <var>actualResponse</var>'s
4024-
<a for=response>location URL</a>'s <a for=url>origin</a>, then return a <a>network error</a>.
4027+
<var>locationURL</var> <a>includes credentials</a>, and <var>request</var>'s
4028+
<a for=request>origin</a> is not <a>same origin</a> with <var>locationURL</var>'s
4029+
<a for=url>origin</a>, then return a <a>network error</a>.
40254030

40264031
<li>
40274032
<p>If <var>request</var>'s <a for=request>response tainting</a> is "<code>cors</code>" and
4028-
<var>actualResponse</var>'s <a for=response>location URL</a>
4029-
<a lt="include credential">includes credentials</a>, then return a <a>network error</a>.
4033+
<var>locationURL</var> <a>includes credentials</a>, then return a <a>network error</a>.
40304034

40314035
<p class=note>This catches a cross-origin resource redirecting to a same-origin URL.
40324036

40334037
<li><p>If <var>actualResponse</var>'s <a for=response>status</a> is not 303, <var>request</var>'s
40344038
<a for=request>body</a> is non-null, and <var>request</var>'s <a for=request>body</a>'s
40354039
<a for=body>source</a> is null, then return a <a>network error</a>.
40364040

4037-
<li><p>If <var>actualResponse</var>'s <a for=response>location URL</a>'s <a for=url>origin</a> is
4038-
not <a>same origin</a> with <var>request</var>'s <a for=request>current URL</a>'s
4039-
<a for=url>origin</a> and <var>request</var>'s <a for=request>origin</a> is not <a>same origin</a>
4040-
with <var>request</var>'s <a for=request>current URL</a>'s <a for=url>origin</a>, then set
4041-
<var>request</var>'s <a for=request>tainted origin flag</a>.
4041+
<li><p>If <var>locationURL</var>'s <a for=url>origin</a> is not <a>same origin</a> with
4042+
<var>request</var>'s <a for=request>current URL</a>'s <a for=url>origin</a> and
4043+
<var>request</var>'s <a for=request>origin</a> is not <a>same origin</a> with <var>request</var>'s
4044+
<a for=request>current URL</a>'s <a for=url>origin</a>, then set <var>request</var>'s
4045+
<a for=request>tainted origin flag</a>.
40424046

40434047
<li>
40444048
<p>If one of the following is true
@@ -4069,7 +4073,7 @@ optional <i>CORS-preflight flag</i>, run these steps:
40694073
<p class="note no-backref"><var>request</var>'s <a for=request>body</a>'s <a for=body>source</a>'s
40704074
nullity has already been checked.
40714075

4072-
<li><p>Append <var>actualResponse</var>'s <a for=response>location URL</a> to <var>request</var>'s
4076+
<li><p><a for=list>Append</a> <var>locationURL</var> to <var>request</var>'s
40734077
<a for=request>URL list</a>.
40744078

40754079
<li><p>Invoke <a>set <var>request</var>'s referrer policy on redirect</a> on <var>request</var> and

0 commit comments

Comments
 (0)