Skip to content

Commit 9849742

Browse files
committed
inspector: convert to buffer in inspector instead of http2 core
Signed-off-by: Darshan Sen <raisinten@gmail.com>
1 parent 49ff459 commit 9849742

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

lib/internal/inspector/network_http2.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
NGHTTP2_NO_ERROR,
3030
} = internalBinding('http2').constants;
3131
const EventEmitter = require('events');
32+
const { Buffer } = require('buffer');
3233

3334
const kRequestUrl = Symbol('kRequestUrl');
3435

@@ -126,13 +127,40 @@ function onClientStreamError({ stream, error }) {
126127
/**
127128
* When a chunk of the request body is being sent, cache it until `getRequestPostData` request.
128129
* https://chromedevtools.github.io/devtools-protocol/1-3/Network/#method-getRequestPostData
129-
* @param {{ stream: import('http2').ClientHttp2Stream, chunk: Buffer }} event
130+
* @param {{
131+
* stream: import('http2').ClientHttp2Stream,
132+
* writev: boolean,
133+
* data: Buffer | string | Array<Buffer | {chunk: Buffer|string, encoding: string}>,
134+
* encoding: string,
135+
* }} event
130136
*/
131-
function onClientStreamBodyChunkSent({ stream, chunk }) {
137+
function onClientStreamBodyChunkSent({ stream, writev, data, encoding }) {
132138
if (typeof stream[kInspectorRequestId] !== 'string') {
133139
return;
134140
}
135141

142+
let chunk;
143+
144+
if (writev) {
145+
if (data.allBuffers) {
146+
chunk = Buffer.concat(data);
147+
} else {
148+
const buffers = [];
149+
for (let i = 0; i < data.length; ++i) {
150+
if (typeof data[i].chunk === 'string') {
151+
buffers.push(Buffer.from(data[i].chunk, data[i].encoding));
152+
} else {
153+
buffers.push(data[i].chunk);
154+
}
155+
}
156+
chunk = Buffer.concat(buffers);
157+
}
158+
} else if (typeof data === 'string') {
159+
chunk = Buffer.from(data, encoding);
160+
} else {
161+
chunk = data;
162+
}
163+
136164
Network.dataSent({
137165
requestId: stream[kInspectorRequestId],
138166
timestamp: getMonotonicTime(),

0 commit comments

Comments
 (0)