sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

JSON response isn't parsed #2045

Closed viceice closed 2 years ago

viceice commented 2 years ago

Describe the bug

Actual behavior

When setting responseType=json and dong a get to https://gcr.io/v2/cloudsql-docker/gce-proxy/tags/list?n=10000 the body is not deserialized.

Expected behavior

Response body should be an object instead of a string

Code to reproduce

consat url = 'https://gcr.io/v2/cloudsql-docker/gce-proxy/tags/list?n=10000';
const resp = await got(url, {responseType: 'json'});
console.dir({url, res: typeof resp.body, headers: resp.headers});

{
  url: 'https://gcr.io/v2/cloudsql-docker/gce-proxy/tags/list?n=10000',
  res: 'string',
  headers: [Object: null prototype] {
    ':status': 200,
    'docker-distribution-api-version': 'registry/2.0',
    'content-type': 'application/json',
    'content-length': '7145',
    'content-encoding': 'gzip',
    date: 'Mon, 23 May 2022 07:52:07 GMT',
    server: 'Docker Registry',
    'cache-control': 'private',
    'x-xss-protection': '0',
    'x-frame-options': 'SAMEORIGIN',
    'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
    [Symbol(nodejs.http2.sensitiveHeaders)]: []
  }
}