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

Error response body is not decompressed for streams #1142

Closed
2 tasks done
adityapatadia opened this issue Apr 1, 2020 · 1 comment
Closed
2 tasks done

Error response body is not decompressed for streams #1142

adityapatadia opened this issue Apr 1, 2020 · 1 comment

Comments

@adityapatadia
Copy link

Describe the bug

  • Node.js version: 12.16.1
  • OS & version: MacOS 10.15

Actual behavior

When stream throws error, the event listener sends error object. The error.response.body should be decompressed when got.stream() is passed decompress: true option but actually, the response is gzip compressed if the server sends HTTPError with gzip encoding.

Second issue is that error.response.body is a buffer but ideally it should be stream.
...

Expected behavior

  1. Response should be decompressed inside error object
  2. The response should also be stream rather than buffer.
    ...

Code to reproduce

const got = require('got');

let stream = got("https://www.gumlet.com/non-exisent-path", {
  isStream: true,
  method: "GET",
  decompress: true,
  headers: {}
});

stream.on("response", (response) => {
  console.log(response.headers);
  console.log(response.statusCode)
});

stream.on("error", (err) => {

  console.log("This is compressed:", err.response.body); // this should be decompressed.

  console.log(Buffer.isBuffer(err.response.body)); // response.body is a buffer but ideally that should also be stream.
});

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

Fixed in #1051
Test: bf0b0cd

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

2 participants