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.

Fixes whatwg#674.
  • Loading branch information
harrishancock committed Feb 28, 2018
1 parent ae71682 commit e0049c6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions fetch.bs
Expand Up @@ -5088,8 +5088,9 @@ 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>If <var>input</var> is <a for=Body>disturbed</a> or <a for=Body>locked</a> and
<var>init</var>'s <code>body</code> member is not present, 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 @@ -5351,7 +5352,8 @@ constructor must run these steps:
<!-- 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 run these
substeps:

<ol>
<li>
Expand All @@ -5366,10 +5368,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 +6252,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 e0049c6

Please sign in to comment.