Skip to content

Enable debug information for fetch() via NODE_DEBUG=http #2191

@dimw

Description

@dimw

What is the problem this feature will solve?

The HTTP debug information for node-fetch can be turned on by setting the the environment variable NODE_DEBUG=http:

// node-fetch.test.js
const fetch = require('node-fetch');

fetch('https://github.com')
  .then(({statusText}) => console.log(statusText));
$ NODE_DEBUG=http node node-fetch.test.js
HTTP 22032: call onSocket 0 0
HTTP 22032: createConnection github.com:443::::::::::::::::::::: [Object: null prototype] {
  protocol: 'https:',
  slashes: true,
[redacted]
HTTP 22032: AGENT incoming response!
OK
HTTP 22032: AGENT socket.destroySoon()
HTTP 22032: CLIENT socket onClose
HTTP 22032: removeSocket github.com:443::::::::::::::::::::: writable: false
HTTP 22032: HTTP socket close

Unfortunately, there is no HTTP debug information is shown when the native fetch() implementation is used:

// fetch.test.js
fetch('https://github.com')
  .then(({statusText}) => console.log(statusText));
$ NODE_DEBUG=http node fetch.test.js
OK

Seeing the HTTP request object can be considered as useful for debugging.

What is the feature you are proposing to solve the problem?

  • Either display the HTTP debug statement for the native fetch() when NODE_DEBUG=http is active or
  • introduce a new flag to display HTTP debug output.

What alternatives have you considered?

The native fetch() is presenting more information when NODE_DEBUG=net,stream is used. This information is, however, not suitable for HTTP debugging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions