Skip to content
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

Why doesn't the "body" member of RequestInit have a default value? #933

Open
bzbarsky opened this issue Sep 10, 2019 · 4 comments
Open

Why doesn't the "body" member of RequestInit have a default value? #933

bzbarsky opened this issue Sep 10, 2019 · 4 comments
Labels
needs implementer interest Moving the issue forward requires implementers to express interest topic: api

Comments

@bzbarsky
Copy link

The member is defined at https://fetch.spec.whatwg.org/#dom-requestinit-body as follows:

  BodyInit? body;

The only consumer of the RequestInit dictionary is https://fetch.spec.whatwg.org/#dom-request which does this:

If either init["body"] exists and is non-null or inputBody is non-null, and request’s method is GET or HEAD, then throw a TypeError.

and

If init["body"] exists and is non-null, then:

In both cases, "does not exist" and "exists but is null" are treated identically, so it seems like the IDL could just say:

BodyInit? body = null;

and not worry about the "does not exist" case.

@annevk
Copy link
Member

annevk commented Sep 10, 2019

Step 14 of the constructor reads

If init is not empty, then:

which would be affected by this change.

What is a little weird to me though is that if you do new Request(oldRequestWithBody, { body: null }) it doesn't seem like the body would get cleared. Maybe I'm missing something with disturbed/locked though, would have to investigate more deeply.

@bzbarsky
Copy link
Author

Ah, good catch re step 14. So I guess then the question is indeed what should happen in the { body: null } but nothing else set case.

@annevk
Copy link
Member

annevk commented Jan 30, 2021

x = new Request("about:blank", { method: "POST", body: "test" });
copyX = new Request(x, { body: null });
copyX.text().then(console.log);

gives "test" in all browsers.

Is this something we want to fix?

cc @wanderview @youennf @evilpie

@annevk annevk added the needs implementer interest Moving the issue forward requires implementers to express interest label Jan 30, 2021
@wanderview
Copy link
Member

cc @yutakahirano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs implementer interest Moving the issue forward requires implementers to express interest topic: api
Development

No branches or pull requests

3 participants