Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/inspector/network_http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ function onClientStreamBodyChunkSent({ stream, writev, data, encoding }) {
const buffers = [];
for (let i = 0; i < data.length; ++i) {
if (typeof data[i].chunk === 'string') {
buffers.push(Buffer.from(data[i].chunk, data[i].encoding));
buffers[buffers.length] = Buffer.from(data[i].chunk, data[i].encoding);
} else {
buffers.push(data[i].chunk);
buffers[buffers.length] = data[i].chunk;
}
}
chunk = Buffer.concat(buffers);
Expand Down
47 changes: 47 additions & 0 deletions test/parallel/test-inspector-network-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ const handleStream = common.mustCallAtLeast((stream, headers) => {
}, kTimeout);
}));
break;
case '/writev':
stream.on('data', (chunk) => {
body += chunk;
});

stream.on('end', common.mustCall(() => {
assert.strictEqual(body, JSON.stringify(requestBody));
stream.respond(responseHeaders);
stream.end(serverResponse);
}));
break;
case '/trigger-error':
stream.close(http2.constants.NGHTTP2_STREAM_CLOSED);
stream.on('error', common.expectsError({
Expand Down Expand Up @@ -283,6 +294,40 @@ async function testHttp2(secure = false) {
assert.ok(delta > kDelta);
}

async function testHttp2Writev() {
const origin = `http://localhost:${http2Server.address().port}`;
const body = JSON.stringify(requestBody);

const requestWillBeSent = once(session, 'Network.requestWillBeSent');
const loadingFinished = once(session, 'Network.loadingFinished');
session.on('Network.loadingFailed', common.mustNotCall());

const client = http2.connect(origin);
const request = client.request({
...requestHeaders,
[http2.constants.HTTP2_HEADER_PATH]: '/writev',
});
// Corked writes that mix a string and a Buffer are sent as a single writev.
request.cork();
request.write(body.slice(0, 5));
request.write(Buffer.from(body.slice(5)));
request.end();

request.resume();
request.on('end', () => {
client.close();
});

const [ requestEvent ] = await requestWillBeSent;
// The request body can only be read once it has been sent completely.
await loadingFinished;

const { postData } = await session.post('Network.getRequestPostData', {
requestId: requestEvent.params.requestId
});
assert.strictEqual(postData, body);
}

async function testHttp2Error(secure = false) {
const port = (secure ? http2SecureServer : http2Server).address().port;
const origin = (secure ? 'https' : 'http') + `://localhost:${port}`;
Expand Down Expand Up @@ -321,6 +366,8 @@ const testNetworkInspection = async () => {
session.removeAllListeners();
await testHttp2(true);
session.removeAllListeners();
await testHttp2Writev();
session.removeAllListeners();
await testHttp2Error();
session.removeAllListeners();
await testHttp2Error(true);
Expand Down
Loading