nodejs / nodejs/undici

[diagnostics_channel] support body received?

Open
#1,342 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
7.7k
Forks
880
Avg merge
2d 16h
Merged PRs (30d)
68

Description

This would solve...

In a library I am working on, they had 2 events (request & response) that would fire before and after a request was made. The purpose of these events was for analytics (ie. receiving a "weird" response code and checking the body). With undici, I'm hoping that these events can be removed entirely and instead use the diagnostics_channel support (the library only supports v16.9.0+).

The implementation should look like...

In the request property, the body is sent but under a symbol property and uncloned. Exposing it publicly (maybe under bodyReceived or some other name) and cloning it so it can be used twice would be exactly what I need. Receiving a buffer would also be very useful.

Since it is using request, rather than fetch, it is using a node Readable stream so we can't just tee the stream.

I have also considered...

Additional context

The implementation previously used was not performant and didn't need to be because it was only supposed to be used when something majorly messed up.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the diagnostics_channel request property and how the received body is currently stored as a symbol-backed, uncloned Node.js Readable stream. Define the public body representation and duplication behavior, then verify that diagnostics_channel consumers can inspect the body twice, including the requested buffer use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.