-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that a Request object can be used as RequestInit #1486
Comments
Can you remind me what |
Surprisingly, it becomes an empty object. The only way I could convert 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()); // hello! Here are the results:
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: 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. |
Oh, the reason it becomes empty is presumably because And I guess one way to read this is as a request to expose duplex on |
Yes. Or more precisely to update this type:
to be:
https://fetch.spec.whatwg.org/#request-class In other words, User-Agents should expect a |
I suppose that could be an alternative if we decide not to expose |
If it's helpful, I would expect user agents to set the |
This will be fixed by #1493. |
When constructing a
Request
object, this works in every browser: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 thebase
completely.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 there is a body on the request.
body
is droppedUncaught TypeError: Failed to construct 'Request': The `duplex` member must be specified for a request with a streaming body
Could the spec clarify that Request should work as a RequestInit?
The text was updated successfully, but these errors were encountered: