inspector,http: support builtin http request bodies#62915
inspector,http: support builtin http request bodies#62915GrinZero wants to merge 3 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
metcoder95
left a comment
There was a problem hiding this comment.
lgtm, it just seems that is gonna need a documentation for the new dcs
|
Thanks for the feedback. I’ve updated the documentation in Specifically, I added/updated entries for:
I also aligned the wording and structure with the existing Node.js docs style for built-in channels. |
|
A slight push, hoping that a maintainer will notice. |
|
Sorry for the ping, @legendecas If you have some time, could you please help review this PR and trigger CI? This PR fixes an issue where the network inspector does not show Thanks a lot! |
|
push, request-ci plz |
|
Ill try to review the PR later, I think it's important we make sure it doesn't leak memory or keep the body buffer reference alive, which can exhaust resource quickly @ShogunPanda ptal |
I'll go explore the issue you mentioned |
|
Thanks for raising this concern. I did a focused memory/lifetime check for this PR, mainly around two questions:
Based on the current implementation and local testing, I do not see evidence that this PR keeps the original JS buffers alive. For both request and response bodies, the payload bytes are copied into inspector-owned storage before being retained by So the inspector is retaining copied payload bytes, not the original userland Buffer objects. I also ran a repeated-request memory test with explicit |
|
The test plan above was proposed by AI, and I reviewed it. For the first test, it uses The second test is a stress test. It lowers |
Signed-off-by: GrinZero <774933704@qq.com>
ab906d5 to
194a5fd
Compare
|
I merged the main branch code to avoid CI errors. |

Summary
This PR adds builtin
http/httpsrequest-body support to network inspection, soNetwork.getRequestPostDataworks for text request bodies while preserving the existing rejection behavior for binary request bodies.It also moves builtin
httpresponse-body tracking to a raw-byte hook beforeIncomingMessagedecoding, so response inspection remains correct even when user code callsresponse.setEncoding(...).This closes part of the remaining
postDatagap tracked in the network-inspection stabilization issue.Problem
Builtin
http/httpsnetwork inspection currently emits:Network.requestWillBeSentNetwork.responseReceivedNetwork.loadingFinishedHowever, it does not emit request-body data for the builtin
httpclient path. As a result,Network.getRequestPostDatacannot return POST data for builtinhttp/httpsrequests.In the tracking issue for stabilizing network inspection, builtin
http/httpsrequestpostDatais still marked as needing further investigation. This change targets that specific gap.While working on that, this PR also addresses an important response-side edge case: listening to
IncomingMessage'data'events is not a stable source of raw bytes.When user code calls:
the chunks observed by userland change from
Bufferobjects into strings. The inspector protocol expects byte-oriented payloads forNetwork.dataReceivedandNetwork.dataSent, so reconstructing bytes from already-decoded strings is only a best-effort fallback and can lose the original payload.Approach
1. Reuse the existing request buffering pipeline
This change does not modify the CDP schema or the C++ buffering logic in
NetworkAgent.Instead, it reuses the existing pipeline already used by other transports:
2. Add builtin
httprequest-body diagnostics eventsThe builtin
httpclient now publishes:http.client.request.bodyChunkSenthttp.client.request.bodySentThese events are emitted from the
ClientRequestwrite path before HTTP framing is applied, so the inspector sees the original user payload rather than chunked-transfer framing bytes.That makes the behavior consistent with the existing
undiciandhttp2network-inspection implementations.3. Capture builtin
httpresponse bytes before decodingFor responses, this PR intentionally avoids relying on
IncomingMessage.on('data')innetwork_http.js.Instead, it adds:
http.client.response.bodyChunkReceivedfrom the HTTP parser body callback in
_http_common.js.That hook runs before
Readable.setEncoding()transforms chunks for userland, so the inspector always receives raw bytes. This avoids issues such as:dataLengthor wrong event shape when user code receives stringsNetwork.dataReceived4. Prefer raw bytes over string re-encoding
A temporary compatibility fix could convert string chunks back into
Buffers, but that is not equivalent to preserving the original bytes:setEncoding()are no longer raw bytesSo the final implementation moves the builtin
httpresponse path to the same principle used by external tooling: capture bytes first, decode later if needed.This is also consistent with the general handling in
node-network-devtools, where network payload processing is built aroundBufferdata rather than post-decoding string chunks.Behavior
After this change:
httpandhttpsPOST requests with UTF-8 text bodies are available throughNetwork.getRequestPostDatahttpresponse inspection continues to work even if user code callsresponse.setEncoding('utf8')Tests
This PR adds and extends coverage in:
test/parallel/test-diagnostics-channel-http.jstest/parallel/test-inspector-network-http.jsThe updated tests cover:
write()andend()httpandhttpsNetwork.getRequestPostDatafor text bodiesresponse.setEncoding('utf8')Verification
Verified locally with:
Both tests passed locally with the built
out/Release/node.Refs