-
Notifications
You must be signed in to change notification settings - Fork 315
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
FetchEvent.respondWith does something weird with the body of a response #850
Comments
cc: @jungkees, the author of ccff1f1. I guess the description is from the bottom of https://fetch.spec.whatwg.org/#dom-request. That works because Request doesn't expose |
Basically, I wanted to avoid cloning the body not to require additional memory space. I still want to find a way. Do the following steps make sense? response: a Response object (resolved from a promise) passed to respondWith(r)
Or, set the newResponse's body to the result of extracting the package data out of response's body's stream will do? |
If you want to clone a response, use the algorithms provided in Fetch. (Although those do not account for what follows at the moment, unfortunately.) If we take a step back and look at how this maps to JavaScript, I think |
I'm confused. (As usual.) Why do we need to clone at all? Can't respondWith() just be spec'd to read the stream from the response per normal? It seems this should leave the stream disturbed/locked just as if javascript had read the stream. |
How do you get the bytes read across realms (and the |
My understanding is our plan is to use pipe. Something like this.
|
From an implementation perspective we effectively serialize the Response into a C++ representation. That may or may not become another Response object depending on what initiated the request. So I guess in spec language I would say you need to create a new internal response (lower case r) with a pipe for a body. Then the original body stream is .pipeTo()'d the new response's body. (Which I think matches what @yutakahirano just posted.) |
Yeah, that sounds reasonable. (And would indeed map to some kind of structured clone operation in an all-JavaScript-world.) |
Except that "cloning" implies that the original object is still usable. This is consuming the original object. Maybe I'm splitting hairs, but I think its an important distinction and differs from what structured cloning normally does AFAIK. |
This change temporarily describes it with the steps that read all bytes from dummy stream set for the input response's body. Eventually, we'll rewrite it using stream's pipeTo behavior when it's ready: #850 (comment)
pipeTo says the method is still in some flux. So, I just temporarily changed the steps (6afc3d8) to #850 (comment) with leaving an issue note to use #850 (comment) when it's ready. Also, it'll be great if you can make the pipeTo an extracted algorithm so other algorithms can directly invoke. (/cc @yutakahirano, @domenic) |
@wanderview "structured cloning" has a concept of transfering and detaching the original object, sure, and that happens for body, but e.g., |
Pre F2F notes: I think this is just spec work remaining. |
F2F: @yutakahirano is working on #934. I think the PR will resolve this issue. |
The current description pretends that a ReadableStream can be passed from one realm to another, which is wrong. This change changes the description so that it creates a new ReadableStream and passes Uint8Array objects from the old ReadableStream to the new one. This is discussed at whatwg/fetch#330. This change fixes w3c#850 as well.
The current description pretends that a ReadableStream can be passed from one realm to another, which is wrong. This change changes the description so that it creates a new ReadableStream and passes Uint8Array objects from the old ReadableStream to the new one. This is discussed at whatwg/fetch#330. This change fixes w3c#850 as well.
I'll backport 6c2b3f1 to V1. |
Backport 6c2b3f1 that closes #850 to V1. Add @yutakahirano to acknowledgements section.
In the algorithm describing respondWith the following steps exist:
I think this is incorrect, although I'm not entirely sure what it is trying to do.
What it seems to say it is doing is assigning a new body to response's body (not sure how that is possible, response's body is defined as being the body of response's associated response. There doesn't seem to be a way to change the body of just the
Response
object while leaving the body of the underlying response alone). It then goes and reads all the bytes from this newly created empty body.I'm guessing the intended effect is to leave the javascript
Response
object with a disturbed body, which happens to be an empty stream, while leaving the underlying response alone. But the fetch spec doesn't allow decoupling the body of theResponse
object from the body of the associated response, so what is written doesn't actually work.The text was updated successfully, but these errors were encountered: