Re: [whatwg/fetch] Ensure that a Request object can be used as RequestInit (Issue #1486)

> Can you remind me what ...base ends up doing? 

Surprisingly, it becomes an _empty_ object.

The only way I could convert `Request` to a "plain" object was like this:
```js
const base = new Request('https://example.com', { method: 'POST', body: 'hello!', headers: { 'accept': 'text/html' }});

const init = {};
for (const property in base) {
  init[property] = base[property];
}

const request = new Request('https://new.example.com', {
  ...init,
  duplex: 'half'
});
console.log(request.headers.get('accept')); // text/html
console.log(request.url); // https://new.example.com

console.log(await request.text());  // https://new.example.com

```

Here are the results:
| Browser      | Works | Result |
| ----------  | ------- | ------- |
| Firefox       | ❌         | `body` is dropped
| Chrome     |  ✅         | threw an error unless I added the `duplex` option above |
| Safari        | ✅         | 
| Deno         | ✅         |

> The last case looks like a result from the recent changes around upload streams.

Yes. That is exactly right. In Chrome <= 104, Chrome had the same behavior as Firefox (dropping the body). Chrome >= 105, the error starts being thrown. I opened a bug here:
https://bugs.chromium.org/p/chromium/issues/detail?id=1360943


----------------------

It seems like there isn't a "clean" way to merge two request objects or even simply override the URL of an existing Request object.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1486#issuecomment-1250073926

You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/1486/1250073926@github.com>

Received on Saturday, 17 September 2022 13:41:43 UTC