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

gzip support? #17

Open
makc opened this issue May 30, 2015 · 14 comments
Open

gzip support? #17

makc opened this issue May 30, 2015 · 14 comments

Comments

@makc
Copy link

makc commented May 30, 2015

I was getting 404 for some file before I did this

    xhr.open(method, url, true)
    if XMLHttpRequest.prototype._restrictedHeaders
        delete XMLHttpRequest.prototype._restrictedHeaders['accept-encoding']
        xhr.setRequestHeader('Accept-Encoding', 'gzip, deflate')

Now I don't get 404, but the data is obviously garbage. Is there easy way to get unzipped content in this case?

@pwnall
Copy link
Owner

pwnall commented May 30, 2015

The server must have a weird configuration.

I'd look into zlib, it is built into node.js (at least for 0.10 and 0.12).
https://nodejs.org/docs/v0.10.0/api/zlib.html

This sounds like an useful thing to support out of the box. Sorry I don't have time to work on it right now! We can leave the issue open for when I have time to get to it.

@makc
Copy link
Author

makc commented Jun 1, 2015

yes, server does not serve the file non-zipped for some reason. I ended up using request

@jimmyangel
Copy link

Do you have any plans to add gzip support to this library? Thank you.

@luxalpa
Copy link

luxalpa commented Aug 23, 2018

Angular's Server Side rendering depends on this project and requires GZIP support :(

@pwnall
Copy link
Owner

pwnall commented Aug 23, 2018

For Angular folks -- I'm at Google now, so I could justify spending some time on this if it's helpful to Angular. Please reach out to me if you'd like to discuss.

@moxival
Copy link

moxival commented Aug 24, 2018

The Angular SSR can have tangible benefit receiving gzipped content as the remote requests are probably the slowest part of our project.

@benjamingr
Copy link

I patched this into my own implementation with the following diff at Testim:

             } else {
                 buffer = this._concatBuffers(this._responseParts);
             }
+            // temporary workaround for transport encoding parsing
+            if (this._responseHeaders['content-encoding'] && this._responseHeaders['content-encoding'] === 'gzip') {
+                buffer = require('zlib').gunzipSync(buffer);
+            }
+            console.log('response parse', this._responseHeaders);
             this._responseParts = null;
             switch (this.responseType) {
                 case 'text':

Feel free to use this (it's very basic and mostly incorrect since it doesn't stream the zipped data), a more correct implementation would reuse the logic for this from superagent or request.

It worked for me, feel free to use this.

@mahpour
Copy link

mahpour commented Aug 9, 2019

I patched this into my own implementation with the following diff at Testim:

             } else {
                 buffer = this._concatBuffers(this._responseParts);
             }
+            // temporary workaround for transport encoding parsing
+            if (this._responseHeaders['content-encoding'] && this._responseHeaders['content-encoding'] === 'gzip') {
+                buffer = require('zlib').gunzipSync(buffer);
+            }
+            console.log('response parse', this._responseHeaders);
             this._responseParts = null;
             switch (this.responseType) {
                 case 'text':

Feel free to use this (it's very basic and mostly incorrect since it doesn't stream the zipped data), a more correct implementation would reuse the logic for this from superagent or request.

It worked for me, feel free to use this.

Can you please explain where/how this should be applied?

@benjamingr
Copy link

This is a diff file, you can typically apply it with the patch command http://man7.org/linux/man-pages/man1/patch.1.html

@mahpour
Copy link

mahpour commented Aug 9, 2019

This is a diff file, you can typically apply it with the patch command http://man7.org/linux/man-pages/man1/patch.1.html

I understand. but which file?

@mahpour
Copy link

mahpour commented Aug 12, 2019

I figured it out. I used the script patching to apply the patch after npm install.
Thanks to John Liu from:
http://johnliu.net/blog/2018/12/hot-patching-our-dependencies-with-patch-package

@RomanChygryn
Copy link

Is this still not supported by Angular Universal?
Logs from ssr throws mi this error Refused to set unsafe header "Accept-Encoding"
I added "Accept-Encoding" header to all requests to enable gzip.

I need to know if i understand correctly: Angular Universal use xhr2 for all requests, and xhr2 not support gzip, thats what my ssr refuse "Accept-Encoding" header, i'm right?

@amakhrov
Copy link

"Accept-Encoding" is not supposed to be set manually at all. Instead, user agent is expected to set it automatically for all outgoing requests, based on what this user agent really supports.

Now, the real question is - does xhr2 support decoding gzipped responses? If yes - it should set this header automatically. Otherwise - curious to know if there are any plans to start supporting it.

@mahpour
Copy link

mahpour commented May 26, 2020

I checked xhr2 used in angular 9 universal and it still doesn’t support gzip decompression. I had to create a new patch file and use it in our build process.

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

No branches or pull requests

9 participants