Bug 183703 - [Fetch API] Allow used body replacement in Request constructor
Summary: [Fetch API] Allow used body replacement in Request constructor
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-03-16 11:03 PDT by Harris Hancock
Modified: 2019-04-02 13:54 PDT (History)
6 users (show)

See Also:


Attachments
Patch (4.06 KB, patch)
2019-03-29 16:30 PDT, Chris Dumez
youennf: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Harris Hancock 2018-03-16 11:03:51 PDT
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, in which the author tries to replace a used body, throws a TypeError:

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

Since the second snippet is providing a new body to the constructor, there doesn't seem to be any technical need to throw.

I have a pull request in to change this in the Fetch spec here:

https://github.com/whatwg/fetch/pull/675

Accompanying WPT PR here:

https://github.com/w3c/web-platform-tests/pull/9931
Comment 1 Radar WebKit Bug Importer 2019-03-29 10:26:43 PDT
<rdar://problem/49425609>
Comment 2 Chris Dumez 2019-03-29 16:30:04 PDT
Created attachment 366323 [details]
Patch
Comment 3 Chris Dumez 2019-04-02 11:39:02 PDT
ping review?
Comment 4 youenn fablet 2019-04-02 12:33:30 PDT
Comment on attachment 366323 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=366323&action=review

> Source/WebCore/Modules/fetch/FetchRequest.cpp:241
> +            return Exception {TypeError, "Request input is disturbed or locked."_s };

s/{T/{ T/
Comment 5 Chris Dumez 2019-04-02 13:48:26 PDT
Committed r243757: <https://trac.webkit.org/changeset/243757>