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

Response.body is always empty #1349

Closed
2 tasks done
thetutlage opened this issue Jul 8, 2020 · 10 comments
Closed
2 tasks done

Response.body is always empty #1349

thetutlage opened this issue Jul 8, 2020 · 10 comments

Comments

@thetutlage
Copy link

thetutlage commented Jul 8, 2020

Describe the bug

  • Node.js version: v14.0.0
  • OS & version: MacOS Catalina
  • Got version: 11.5.0

Trying to make a very simple HTTP request and the response body is always empty. Tried reading the docs couple of times, ensuring I haven't missed anything. But nope.

Actual behavior

The response.body is an empty string

Expected behavior

Should return the response returned by the server

Code to reproduce

const got = require("got")
got.get('http://jsonplaceholder.typicode.com/todos/1').then((response) => {
  console.log(response.body)
})

Just to make sure, that there isn't anything wrong on my end. I also tried using the Node.js http client to make the request to the same URL and it works fine.

Sample code for same

http.get('http://jsonplaceholder.typicode.com/todos/1', (response) => {
  let rawData = ''
  response.on('data', (chunk) => { rawData += chunk; })
  response.on('end', () => {
    console.log(rawData)
  });
})

In action

CleanShot 2020-07-08 at 16 31 05

Checklist

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

Haven't been able to dig deeper. But the code works fine on 11.3.0 and not on 11.4.0 and 11.5.0. Seems like on of the following commits have caused the issue

@Giotino
Copy link
Collaborator

Giotino commented Jul 8, 2020

Latest Got (11.5.0)

On my end the body is empty on Node.JS 14.0.0, but it works fine on 14.5.0 (latest version).

@szmarczak
Copy link
Collaborator

Tested on all [supported] latest Node.js and it works as expected. Please update your Node.js version.

@thetutlage
Copy link
Author

@szmarczak Are you collecting points by quickly closing the issues?

When someone creates an issue, they are not opening it to just have fun. First try to have a dialogue. But anyways

Here's the output of tests on node v14.0.0.

Screen Shot 2020-07-08 at 7 06 24 PM

If you suggest to upgrade to v14.5.0, then please share some reasons behind it

@thetutlage
Copy link
Author

ping @sindresorhus ^^

@sindresorhus
Copy link
Owner

Are you collecting points by quickly closing the issues?

Closing an issue just means it's resolved from our perspective. It doesn't mean we won't respond to additional comments.

If you suggest to upgrade to v14.5.0, then please share some reasons behind it

Uhm, the bug is fixed.

@sindresorhus
Copy link
Owner

I feel like you're assuming this is a Got bug, while in fact most bugs in Got are really Node.js bugs. It's just that Got is a heavy user of the Node.js HTTP and stream APIs so Node.js bugs become quite apparent here. We cannot reasonable work around all the Node.js bugs, especially not ones that are already fixed in Node.js patch versions. By not upgrading patch versions, you're also exposing yourself to security vulnerabilities.

For reference, @szmarczak has opened 33 Node.js issues and that's just a small percentage of all the bugs we have encountered.

@thetutlage
Copy link
Author

thetutlage commented Jul 8, 2020

Never strictly said it is a got bug. Also, it is impossible for an outsider to know which bugs falls in the Node.js land and which falls in Got land (you guys have history with the module, so understand the blurry lines better)

Was trying to report what I discovered and shared proper context

  • If it is indeed a Node.js bug earlier discovered by you, then a link to that bug would have answered the question.
  • If it is something you just strongly believe is a Node.js bug, then also, I would have been asked to debug in a certain way and come back with more info.

@sindresorhus
Copy link
Owner

You reported a bug and we provided a solution. I don't really see what the issue is here.

@Hacksore
Copy link

Hacksore commented Jul 14, 2020

To add to the discussion, I found that node.js versions 14.0.0 and 14.1.0 seem to be both having the same issue @thetutlage reported.

Upgrading to at least >= 14.2.0 seems to resolve it from an upgrade perspective.

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

5 participants