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

Question: Why don't constructed Response unpack? #1090

Closed
jimmywarting opened this issue Sep 17, 2020 · 4 comments
Closed

Question: Why don't constructed Response unpack? #1090

jimmywarting opened this issue Sep 17, 2020 · 4 comments

Comments

@jimmywarting
Copy link

jimmywarting commented Sep 17, 2020

I was just wondering why isn't the response unpacked when content encoding is set when constructing and reading a Response?

Example code:

// just to get a dummy gzip'ed blob
gz = new CompressionStream('gzip')
blob = new Blob(['a'.repeat(100)]).stream()
gzipBlob = await new Response(blob.pipeThrough(gz)).blob()

// read
headers = {'content-encoding': 'gzip'}
result = await new Response(gzipBlob, { headers }).blob()
result.size // 24 (maybe expected 100)

is it a bug or by design?
have it something to do with respondWith or that request and response share a common Body mixin?
or maybe the body isn't proper encoded? i have also tried deflate, didn't unpack either

@annevk
Copy link
Member

annevk commented Sep 17, 2020

Content codings are handled at the network layer, not below that.

@jimmywarting
Copy link
Author

jimmywarting commented Sep 17, 2020

Okey, but why?
Was thinking maybe i could use fetch(URL.createObjectURL(gzipBlob)) but just realized i can't set the response header for that.

So if i would do fetchEvent.respondWith(new Response(gzipBlob, { headers })) from a service worker would it be unpacked then in the main thread that made the ajax call?

@annevk
Copy link
Member

annevk commented Sep 17, 2020

I don't think it was a conscious decision other than that it would take effort to move it around and it's not clear how compatible that would be at this point. Also, we shouldn't really add functionality around this until #716 is sorted I think. The underpinnings have too many unknowns.

@jimmywarting
Copy link
Author

Alright, I'm fine with that decision.
I can just use DecompressionStream directly. i was mostly just curios why it didn't work below the network layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants