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

Allow a request body to be a byte sequence/string #1083

Merged
merged 7 commits into from
Aug 27, 2020
Merged

Conversation

annevk
Copy link
Member

@annevk annevk commented Aug 25, 2020

This simplifies things for several callers.

Fixes #1073.


Preview | Diff

This simplifies things for several callers.

Fixes #1073.
@annevk
Copy link
Member Author

annevk commented Aug 25, 2020

I think we could get rid of https://fetch.spec.whatwg.org/#concept-empty-readablestream too if we wanted to as it only has one caller and that might as well create a promise resolved with an empty byte sequence.

I looked elsewhere and I couldn't find specifications using these. E.g., the Encoding Standard depends directly upon Streams.

@ricea as maintainer of Streams this might be of slight interest.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice; nicer than what I was thinking of doing.

Do you think it's worth adding a note for callers that supply strings that they might want to set a Content-Type with a UTF-8 charset, since you're going to UTF-8 encode for them? Or maybe we shouldn't have the string input version, hmmm...

fetch.bs Outdated Show resolved Hide resolved
fetch.bs Outdated Show resolved Hide resolved
@annevk
Copy link
Member Author

annevk commented Aug 25, 2020

I was thinking that since the note links "safely extract" it's clear it'll be UTF-8 and we don't really do anything else for strings these days (and shouldn't).

@domenic
Copy link
Member

domenic commented Aug 25, 2020

That's reasonable. However, I'd still err on the side of removing the string possibility until we have more than one concrete caller that would use it. It appears the only user would be reporting, which would not get much simpler, because it would just switch from "serialize JSON to bytes" to... I guess manually using %JSON.stringify%?

@annevk
Copy link
Member Author

annevk commented Aug 26, 2020

Fair, I'll drop that for now. @yutakahirano opinions on removing the empty ReadableStream primitive?

fetch.bs Outdated
@@ -2489,8 +2477,16 @@ object <var>stream</var>, run these steps:
</ol>

<p>An <dfn export for=ReadableStream id=concept-empty-readablestream>empty</dfn> {{ReadableStream}}
object is the result of <a lt="construct a fixed ReadableStream object">constructing</a> a fixed
{{ReadableStream}} object with an empty list.
object, run these steps:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs rewording if we are to keep the "empty" construct.

@yutakahirano
Copy link
Member

I think we need to fix https://fetch.spec.whatwg.org/#dom-body-body too.

@annevk
Copy link
Member Author

annevk commented Aug 26, 2020

@yutakahirano hey! What fix does that need? Do you think we need to preserve "empty"? Any other thoughts on this PR?

@yutakahirano
Copy link
Member

yutakahirano commented Aug 26, 2020

... or the body definition in https://fetch.spec.whatwg.org/#request-class.

https://fetch.spec.whatwg.org/#concept-body-body expects the body to be a body or null, but with this change (concept) request's body is null or a body or a byte sequence.

@annevk
Copy link
Member Author

annevk commented Aug 26, 2020

Isn't the byte sequence turned into a body well before the Boxy mixin gets hold of it? What about the other questions?

@yutakahirano
Copy link
Member

I'm not sure it is.

https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm creates a Request object from a concept request directly at step 21.3.2.

Let requestObject be a new Request object associated with request and a new associated Headers object whose guard is "immutable".

I'm fine with removing https://fetch.spec.whatwg.org/#concept-empty-readablestream if it's unnecessary.

@yutakahirano
Copy link
Member

Ah I was wrong, that is covered by https://whatpr.org/fetch/1083/ad9a84a...ba5c0f3.html#fetching. Sorry for that.

fetch.bs Outdated Show resolved Hide resolved
fetch.bs Outdated Show resolved Hide resolved
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM but @yutakahirano found bugs that I missed so it'd be good to get his final review :)

Copy link
Member

@yutakahirano yutakahirano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@annevk annevk merged commit 99db8c2 into master Aug 27, 2020
@annevk annevk deleted the annevk/request-body branch August 27, 2020 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Allow strings or byte sequences as bodies?
3 participants