Got: `Response.body` is always empty

Created on 8 Jul 2020  路  10Comments  路  Source: sindresorhus/got

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

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.

Most helpful comment

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

All 10 comments

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

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).

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

@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

ping @sindresorhus ^^

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.

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.

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.

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

darksabrefr picture darksabrefr  路  3Comments

sindresorhus picture sindresorhus  路  3Comments

astoilkov picture astoilkov  路  3Comments

alvis picture alvis  路  3Comments

tkoelpin picture tkoelpin  路  3Comments