From ecdf5cea48ef6fc4abc11fbe31ac984d3ca991c3 Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:00:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20call=20stream.end=20w?= =?UTF-8?q?hen=20POST=20Buffer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/client.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/client.js b/lib/client.js index be00382d0d0..065fb563380 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1862,6 +1862,7 @@ function writeH2 (client, session, request) { stream.cork() stream.write(body) stream.uncork() + stream.end() request.onBodySent(body) request.onRequestSent() } else if (util.isBlobLike(body)) { From fdef1fcd9372ba2b709f25f48e94ef7bac76c12e Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:02:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=E2=9C=85=20add=20test=20POST=20Buf?= =?UTF-8?q?fer=20for=20http2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/http2.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/test/http2.js b/test/http2.js index 46f2ff6755d..d3bc4505ede 100644 --- a/test/http2.js +++ b/test/http2.js @@ -17,7 +17,7 @@ const isGreaterThanv20 = gte(process.version.slice(1), '20.0.0') // https://github.com/nodejs/node/pull/41735 const hasPseudoHeadersOrderFix = gte(process.version.slice(1), '16.14.1') -plan(20) +plan(21) test('Should support H2 connection', async t => { const body = [] @@ -114,6 +114,58 @@ test('Should support H2 connection (headers as array)', async t => { t.equal(Buffer.concat(body).toString('utf8'), 'hello h2!') }) +test('Should support H2 connection(POST Buffer)', async t => { + const server = createSecureServer({ ...pem, allowHTTP1: false }) + + server.on('stream', async (stream, headers, _flags, rawHeaders) => { + t.equal(headers[':method'], 'POST') + const reqData = [] + stream.on('data', chunk => reqData.push(chunk.toString())) + await once(stream, 'end') + t.equal(reqData.join(''), 'hello!') + stream.respond({ + 'content-type': 'text/plain; charset=utf-8', + 'x-custom-h2': 'hello', + ':status': 200 + }) + stream.end('hello h2!') + }) + + server.listen(0) + await once(server, 'listening') + + const client = new Client(`https://localhost:${server.address().port}`, { + connect: { + rejectUnauthorized: false + }, + allowH2: true + }) + + t.plan(6) + t.teardown(server.close.bind(server)) + t.teardown(client.close.bind(client)) + + const sendBody = 'hello!' + const body = [] + console.log(`before request ${sendBody}`) + const response = await client.request({ + path: '/', + method: 'POST', + body: sendBody + }) + console.log(`after request ${sendBody}`) + + response.body.on('data', chunk => { + body.push(chunk) + }) + + await once(response.body, 'end') + t.equal(response.statusCode, 200) + t.equal(response.headers['content-type'], 'text/plain; charset=utf-8') + t.equal(response.headers['x-custom-h2'], 'hello') + t.equal(Buffer.concat(body).toString('utf8'), 'hello h2!') +}) + test('Should support H2 GOAWAY (server-side)', async t => { const body = [] const server = createSecureServer(pem) From 338ee421d1cc9736e0e81102651d0db902f4ada6 Mon Sep 17 00:00:00 2001 From: binsee <5285894+binsee@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:51:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=E2=9C=85=20remove=20debug=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/http2.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/http2.js b/test/http2.js index d3bc4505ede..7be79b021d1 100644 --- a/test/http2.js +++ b/test/http2.js @@ -147,13 +147,11 @@ test('Should support H2 connection(POST Buffer)', async t => { const sendBody = 'hello!' const body = [] - console.log(`before request ${sendBody}`) const response = await client.request({ path: '/', method: 'POST', body: sendBody }) - console.log(`after request ${sendBody}`) response.body.on('data', chunk => { body.push(chunk)