- From: David Barratt <notifications@github.com>
- Date: Thu, 08 Sep 2022 06:27:31 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1486@github.com>
When constructing a `Request` object, this works in every browser: ```js const base = new Request('https://example.com', { headers: { 'accept': 'text/html' }}); const request = new Request('https://new.example.com', base); console.log(request.headers.get('accept')); // text/html console.log(request.url); // https://new.example.com ``` | Browser | Works | | ---------- | ------- | | Firefox | ✅ | | Chrome | ✅ | | Safari | ✅ | | Deno | ✅ | I assumed this was the _prefered_ way to make modifications to a URL of a request object, given that this does **not** work in any browser given that it drops the `headers` from the `base` completely. ```js const base = new Request('https://example.com', { headers: { 'accept': 'text/html' }}); const request = new Request('https://new.example.com', { ...base }); console.log(request.headers.get('accept')); // null console.log(request.url); // https://new.example.com ``` | Browser | Works | | ---------- | ------- | | Firefox | ❌ | | Chrome | ❌ | | Safari | ❌ | | Deno | ❌ | This seems straightforward enough, if you need to change the URL of a request object, pass the existing request object as the second parameter. Things get _really_ weird though when their is a body on the request. ```js const base = new Request('https://example.com', { method: 'POST', body: 'hello!', headers: { 'accept': 'text/html' }}); const request = new Request('https://new.example.com', base); console.log(request.headers.get('accept')); // text/html console.log(request.url); // https://new.example.com console.log(await request.text()); // hello! ``` | Browser | Works | Result | | ---------- | ------- | ------- | | Firefox | ❌ | `body` is dropped | Chrome | ❌ | `Uncaught TypeError: Failed to construct 'Request': The `duplex` member must be specified for a request with a streaming body` | | Safari | ✅ | | Deno | ✅ | Could the spec clarify that Request should work as a RequestInit? -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1486 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/fetch/issues/1486@github.com>
Received on Thursday, 8 September 2022 13:27:45 UTC