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

Decoding Gzipped Content #148

Open
rahulmamgain opened this issue Jan 16, 2018 · 4 comments
Open

Decoding Gzipped Content #148

rahulmamgain opened this issue Jan 16, 2018 · 4 comments

Comments

@rahulmamgain
Copy link

While working with the latest eureka server. I'm running the following docker image docker image

The setup is as following

The basic code is below

var resilientClient= Resilient({
    discovery: {
        servers: ['http://localhost:8080/'],
        headers: {
            Accept: 'application/json'
        }
    }
});
var servers = [
    'http://localhost:8080/'
];
resilientClient.use(eurekaMiddleware({
    'path': "eureka/v2/apps",
    'serviceName': "MY_REST_API"
}));
resilientClient.discoveryServers(servers);
  • The problem I face is when the response is Gzipped from the eureka server hence can not be parsed directly as xml.

  • I did try different options but none worked for me, As a final solution I had to edit http.js

https://github.com/resilient-http/resilient.js/pull/147/files

this seems to work well.

My two questions are

  1. Is there any way to achieve this without this code change.
  2. If not, is http js the right place to put in this hook.

Thanks

@h2non
Copy link
Contributor

h2non commented Jan 16, 2018

This should not be actually needed. Assuming you are using node.js, request package would transparently handle gzip decoding for you.

Be sure Eureka server is providing the valid HTTP hader gzip response.

@rahulmamgain
Copy link
Author

Be sure Eureka server is oroviding the valid HTTP hader gzip response.

Eureka server is overriding the response header content-encoding.

that's what i rely on while parsing the response

    httpRequest.on('response', function(response) {
      switch (response.headers['content-encoding']) {
          // or, just use zlib.createUnzip() to handle both cases
          case 'gzip':
              console.log("gzip");
              response.pipe(zlib.createGunzip()).pipe(response);
              break;
          case 'deflate':
              response.pipe(zlib.createInflate()).pipe(response);
              break;
          default:
              break;
      }
    });

Assuming you are using node.js, request package would transparently handle gzip decoding for you.

That's why I also assumed, but either that's not happening, or i'm missing something very obvious.

@danielsan
Copy link
Contributor

I'm facing the same problem right now with Eureka.

I even attempted to gunzip the content within my middleware but the res.body is already a string when it gets to the middleware and there's no property/accessor to get the raw data sent from the remote server

@danielsan
Copy link
Contributor

@rahulmamgain, I'd just remove the console.log from that file so it is one less obstacle for this pull request to be accepted

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

3 participants