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

HTTP status 204 with a content-encoding: gzip #857

Closed
vicanso opened this issue Jan 18, 2016 · 10 comments
Closed

HTTP status 204 with a content-encoding: gzip #857

vicanso opened this issue Jan 18, 2016 · 10 comments

Comments

@vicanso
Copy link
Contributor

vicanso commented Jan 18, 2016

HTTP endpoint that returns a 204 with a content-encoding: gzip, it will throw Error [Error: unexpected end of file] errno: -5, code: 'Z_BUF_ERROR'.

@yourcontainer
Copy link

+1

@focusaurus
Copy link
Contributor

Perhaps we can sanity check Content-Length header before unzipping? In node I think we just .pipe() into a zlib stream but perhaps that doesn't handle zero-size payload properly. Anyone care to code a unit test and a fix and submit a pull request?

@sheltonial
Copy link

+1

@hustcer
Copy link

hustcer commented Aug 31, 2016

+1

@kornelski
Copy link
Contributor

I can't fix this without more information. Please don't +1, as this does not help at all.

Please submit unit tests or a full dump of server and client HTTP headers.

@hustcer
Copy link

hustcer commented Aug 31, 2016

@pornel Sorry, I will add more info later.

@seangarner
Copy link

I doubt this is the cause, but just in case....

A number of conditionals aren't triggered if instantiating the Request class directly with a lowercase method. See ladjs/supertest/pull/371 for an example of how superagent is doing just this and ending up with the same zlib error as in this issue.

@pornel I'm not sure if you'd consider this a superagent bug or not. Personally I think it is because the Request class is exported and documented yet methods are only uppercased when calling the function. If you agree I can open a PR for that.

@hustcer
Copy link

hustcer commented Aug 31, 2016

Just run the following code:

const request = require('superagent');

request
    .get('http://www.dfzq.com.cn/dfzq/dfyw/rzrqbdzq.jsp')
    .buffer()
    .end((err, res) => {

        console.log(err, res);
    });

and you will get the error:

{ Error: unexpected end of file
    at Zlib._handle.onerror (zlib.js:370:17) errno: -5, code: 'Z_BUF_ERROR', response: null } null

@kornelski
Copy link
Contributor

Thanks for the test case with dfzq.com.cn. That helped me diagnose and fix the problem.

@hustcer
Copy link

hustcer commented Sep 3, 2016

@pornel Great !

kornelski added a commit that referenced this issue Sep 4, 2016
* origin/master:
  Normalize spelling of SuperAgent in docs
  Remove superagent-promise-plugin from plugin list
  Fixes #857
  Test trailing junk
  Fixed test
  Formatting
  Drop workaround for ancient Node
  No slacking when constructing JSON.
  Added authentication with client certificates.
  Update Readme.md
  Add .catch for more Promise-like interface
  Include the root file, so that patched agent works
  Correct event.direction in uploads
  Return this when overwriting the response object's on() method
  Changelog
  v2.2.0
  add 'timedout' property to node Request instance
  Add tests to reproduce error when used only .catch without .then
  Unify null querystring values in node and browser environments.
  v2.1.0
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

7 participants