Skip to content

Commit 76578f4

Browse files
authored
Make Request constructor more forgiving
Folks are using the Request constructor in unexpected ways and therefore it is throwing in unexpected ways (in particular when mode is “navigate” or when setting referrer to a cross-origin URL). This will make it throw less, while not really being less useful. Fixes #245.
1 parent 6f223de commit 76578f4

File tree

2 files changed

+47
-39
lines changed

2 files changed

+47
-39
lines changed

Overview.html

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<p><a class="logo" href="https://whatwg.org/"><img alt="WHATWG" height="100" src="https://resources.whatwg.org/logo-fetch.svg" width="100"></a>
99
<h1 id="cors">Fetch</h1>
10-
<h2 class="no-num no-toc" id="living-standard-—-last-updated-15-september-2016">Living Standard — Last Updated 15 September 2016</h2>
10+
<h2 class="no-num no-toc" id="living-standard-—-last-updated-27-september-2016">Living Standard — Last Updated 27 September 2016</h2>
1111

1212
<dl>
1313
<dt>Participate:
@@ -4710,8 +4710,8 @@ <h3 id="request-class"><span class="secno">6.3 </span>Request class</h3>
47104710

47114711
<ol>
47124712
<li><p>If <var>request</var>'s <a href="#concept-request-mode" title="concept-request-mode">mode</a> is
4713-
"<code title="">navigate</code>", <a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a
4714-
<code title="">TypeError</code>.
4713+
"<code title="">navigate</code>", then set it to "<code>same-origin</code>".
4714+
<!-- This works because we have reset request's client too. -->
47154715

47164716
<li><p>Unset <var>request</var>'s <a href="#omit-origin-header-flag">omit-<code>Origin</code>-header flag</a>.
47174717

@@ -4745,25 +4745,29 @@ <h3 id="request-class"><span class="secno">6.3 </span>Request class</h3>
47454745
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#concept-url-parser" title="concept-url-parser">parsing</a>
47464746
<var>referrer</var> with <var>baseURL</var>.
47474747

4748-
<li><p>If <var>parsedReferrer</var> is failure,
4749-
<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code title="">TypeError</code>.
4750-
4751-
<li><p>If <var>parsedReferrer</var>'s
4752-
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#non-relative-flag">non-relative flag</a> is set,
4753-
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#concept-url-scheme" title="concept-url-scheme">scheme</a> is
4754-
"<code>about</code>", and
4755-
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#concept-url-path" title="concept-url-path">path</a> contains a single string
4756-
"<code>client</code>", set <var>request</var>'s
4757-
<a href="#concept-request-referrer" title="concept-request-referrer">referrer</a> to "<code>client</code>" and
4758-
terminate these substeps.
4748+
<li><p>If <var>parsedReferrer</var> is failure, then <a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a
4749+
<code title="">TypeError</code>.
47594750

4760-
<li><p>If <var>parsedReferrer</var>'s
4761-
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#concept-url-origin" title="concept-url-origin">origin</a> is not
4762-
<a class="external" data-anolis-spec="html" href="https://html.spec.whatwg.org/multipage/browsers.html#same-origin">same origin</a> with <var>origin</var>,
4763-
<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code title="">TypeError</code>.
4751+
<li>
4752+
<p>If one of the following conditions is true, then set <var>request</var>'s
4753+
<a href="#concept-request-referrer" title="concept-request-referrer">referrer</a> to "<code>client</code>":
4754+
4755+
<ul class="brief">
4756+
<li><var>parsedReferrer</var>'s <a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#non-relative-flag">non-relative flag</a> is set,
4757+
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#concept-url-scheme" title="concept-url-scheme">scheme</a> is "<code>about</code>", and
4758+
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#concept-url-path" title="concept-url-path">path</a> contains a single string
4759+
"<code>client</code>".
4760+
4761+
<li><var>parsedReferrer</var>'s
4762+
<a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#concept-url-origin" title="concept-url-origin">origin</a> is not
4763+
<a class="external" data-anolis-spec="html" href="https://html.spec.whatwg.org/multipage/browsers.html#same-origin">same origin</a> with <var>origin</var>
4764+
</ul>
4765+
<!-- This can happen when you create a fresh request with values from an older request. Throwing
4766+
would be rather hostile as preventing it requires implementing the same-origin check in
4767+
developer space. -->
47644768

4765-
<li><p>Set <var>request</var>'s
4766-
<a href="#concept-request-referrer" title="concept-request-referrer">referrer</a> to <var>parsedReferrer</var>.
4769+
<li><p>Otherwise, set <var>request</var>'s <a href="#concept-request-referrer" title="concept-request-referrer">referrer</a>
4770+
to <var>parsedReferrer</var>.
47674771
</ol>
47684772

47694773
<li><p>If <var>init</var>'s <code title="">referrerPolicy</code> member is present, set

Overview.src.html

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4640,8 +4640,8 @@ <h3>Request class</h3>
46404640

46414641
<ol>
46424642
<li><p>If <var>request</var>'s <span title=concept-request-mode>mode</span> is
4643-
"<code title>navigate</code>", <span data-anolis-spec=webidl>throw</span> a
4644-
<code title>TypeError</code>.
4643+
"<code title>navigate</code>", then set it to "<code>same-origin</code>".
4644+
<!-- This works because we have reset request's client too. -->
46454645

46464646
<li><p>Unset <var>request</var>'s <span>omit-<code>Origin</code>-header flag</span>.
46474647

@@ -4675,25 +4675,29 @@ <h3>Request class</h3>
46754675
<span data-anolis-spec=url title=concept-url-parser>parsing</span>
46764676
<var>referrer</var> with <var>baseURL</var>.
46774677

4678-
<li><p>If <var>parsedReferrer</var> is failure,
4679-
<span data-anolis-spec=webidl>throw</span> a <code title>TypeError</code>.
4680-
4681-
<li><p>If <var>parsedReferrer</var>'s
4682-
<span data-anolis-spec=url>non-relative flag</span> is set,
4683-
<span data-anolis-spec=url title=concept-url-scheme>scheme</span> is
4684-
"<code>about</code>", and
4685-
<span data-anolis-spec=url title=concept-url-path>path</span> contains a single string
4686-
"<code>client</code>", set <var>request</var>'s
4687-
<span title=concept-request-referrer>referrer</span> to "<code>client</code>" and
4688-
terminate these substeps.
4678+
<li><p>If <var>parsedReferrer</var> is failure, then <span data-anolis-spec=webidl>throw</span> a
4679+
<code title>TypeError</code>.
46894680

4690-
<li><p>If <var>parsedReferrer</var>'s
4691-
<span data-anolis-spec=url title=concept-url-origin>origin</span> is not
4692-
<span data-anolis-spec=html>same origin</span> with <var>origin</var>,
4693-
<span data-anolis-spec=webidl>throw</span> a <code title>TypeError</code>.
4681+
<li>
4682+
<p>If one of the following conditions is true, then set <var>request</var>'s
4683+
<span title=concept-request-referrer>referrer</span> to "<code>client</code>":
4684+
4685+
<ul class=brief>
4686+
<li><var>parsedReferrer</var>'s <span data-anolis-spec=url>non-relative flag</span> is set,
4687+
<span data-anolis-spec=url title=concept-url-scheme>scheme</span> is "<code>about</code>", and
4688+
<span data-anolis-spec=url title=concept-url-path>path</span> contains a single string
4689+
"<code>client</code>".
4690+
4691+
<li><var>parsedReferrer</var>'s
4692+
<span data-anolis-spec=url title=concept-url-origin>origin</span> is not
4693+
<span data-anolis-spec=html>same origin</span> with <var>origin</var>
4694+
</ul>
4695+
<!-- This can happen when you create a fresh request with values from an older request. Throwing
4696+
would be rather hostile as preventing it requires implementing the same-origin check in
4697+
developer space. -->
46944698

4695-
<li><p>Set <var>request</var>'s
4696-
<span title=concept-request-referrer>referrer</span> to <var>parsedReferrer</var>.
4699+
<li><p>Otherwise, set <var>request</var>'s <span title=concept-request-referrer>referrer</span>
4700+
to <var>parsedReferrer</var>.
46974701
</ol>
46984702

46994703
<li><p>If <var>init</var>'s <code title>referrerPolicy</code> member is present, set

0 commit comments

Comments
 (0)