Skip to content

Commit

Permalink
Allow used body replacement in Request constructor
Browse files Browse the repository at this point in the history
Currently, the following code snippet replaces request's body as one
would expect:

  let request = new Request(url, { method: "POST", body: "foo" })
  request = new Request(request, { body: "bar" })

But this snippet throws a TypeError early in Request's constructor:

  let request = new Request(url, { method: "POST", body: "foo" })
  await request.text()  // disturb the body
  request = new Request(request, { body: "bar" })  // throws

This commit's changes allows the latter code snippet to work like the
first one.

Tests: web-platform-tests/wpt#9931.

Fixes #674.
  • Loading branch information
harrishancock authored and annevk committed Mar 17, 2018
1 parent ae71682 commit 5b7dae0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions fetch.bs
Expand Up @@ -5088,9 +5088,6 @@ constructor must run these steps:
<p>Otherwise (<var>input</var> is a {{Request}} object), run these substeps:

<ol>
<li><p>If <var>input</var> is <a for=Body>disturbed</a> or <a for=Body>locked</a>, then
<a>throw</a> a <code>TypeError</code>.

<li><p>Set <var>request</var> to <var>input</var>'s
<a for=Request>request</a>.

Expand Down Expand Up @@ -5348,10 +5345,13 @@ constructor must run these steps:
<a for=request>use-CORS-preflight flag</a>.
</ol>

<li><p>If <var>inputBody</var> is <var>body</var> and <var>input</var> is <a for=Body>disturbed</a>
or <a for=Body>locked</a>, then <a>throw</a> a <code>TypeError</code>.

<!-- Any steps after this must not throw. -->

<li>
<p>If <var>inputBody</var> is non-null, then run these substeps:
<p>If <var>inputBody</var> is non-null and <var>inputBody</var> is <var>body</var>, then:

<ol>
<li>
Expand All @@ -5366,10 +5366,9 @@ constructor must run these steps:
<p class="note no-backref">This makes <var>inputBody</var>'s <a for=body>stream</a>
<a for=ReadableStream>locked</a> and <a for=ReadableStream>disturbed</a> immediately.

<li><p>If <var>inputBody</var> is <var>body</var>, then set <var>body</var> to a new
<a for=/>body</a> whose <a for=body>stream</a> is <var>rs</var>, whose <a for=body>source</a>
is <var>inputBody</var>'s <a for=body>source</a> and whose <a for=body>total bytes</a> is
<var>inputBody</var>'s <a for=body>total bytes</a>.
<li><p>Set <var>body</var> to a new <a for=/>body</a> whose <a for=body>stream</a> is
<var>rs</var>, whose <a for=body>source</a> is <var>inputBody</var>'s <a for=body>source</a>, and
whose <a for=body>total bytes</a> is <var>inputBody</var>'s <a for=body>total bytes</a>.
</ol>

<li><p>Set <var>r</var>'s <a for=Request>request</a>'s <a for=request>body</a> to <var>body</var>.
Expand Down Expand Up @@ -6251,6 +6250,7 @@ Glenn Maynard,
Graham Klyne,
Hal Lockhart,
Hallvord R. M. Steen,
Harris Hancock,
Henri Sivonen,
Henry Story,
Hiroshige Hayashizaki,
Expand Down

0 comments on commit 5b7dae0

Please sign in to comment.