From 121a61b7c734f1199ff4e9c1c8d5656dd8350401 Mon Sep 17 00:00:00 2001 From: Harris Hancock Date: Wed, 28 Feb 2018 10:09:55 -0800 Subject: [PATCH] Allow used body replacement in Request constructor 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 #674. --- fetch.bs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fetch.bs b/fetch.bs index 9d970d437..56d9efe95 100644 --- a/fetch.bs +++ b/fetch.bs @@ -5088,9 +5088,6 @@ constructor must run these steps:

Otherwise (input is a {{Request}} object), run these substeps:

    -
  1. If input is disturbed or locked, then - throw a TypeError. -

  2. Set request to input's request. @@ -5348,10 +5345,14 @@ constructor must run these steps: use-CORS-preflight flag.

+
  • If inputBody is body and input is disturbed + or locked then throw a TypeError. +

  • -

    If inputBody is non-null, then run these substeps: +

    If inputBody is non-null and inputBody is body, then run these + substeps:

    1. @@ -5366,10 +5367,9 @@ constructor must run these steps:

      This makes inputBody's stream locked and disturbed immediately. -

    2. If inputBody is body, then set body to a new - body whose stream is rs, whose source - is inputBody's source and whose total bytes is - inputBody's total bytes. +

    3. Set body to a new body whose stream is + rs, whose source is inputBody's source and + whose total bytes is inputBody's total bytes.

  • Set r's request's body to body. @@ -6251,6 +6251,7 @@ Glenn Maynard, Graham Klyne, Hal Lockhart, Hallvord R. M. Steen, +Harris Hancock, Henri Sivonen, Henry Story, Hiroshige Hayashizaki,