From 1a159b144cd348247b21e77cde8087097ee114f9 Mon Sep 17 00:00:00 2001 From: Carlos Fuentes Date: Wed, 19 Jul 2023 11:00:07 +0200 Subject: [PATCH] refactor: adjust accordingly to review --- lib/client.js | 9 ++++----- lib/core/request.js | 2 ++ test/http2.js | 13 ++++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/client.js b/lib/client.js index 46d374d9213..21cb36ec6cd 100644 --- a/lib/client.js +++ b/lib/client.js @@ -83,7 +83,8 @@ const { HTTP2_HEADER_METHOD, HTTP2_HEADER_PATH, HTTP2_HEADER_CONTENT_LENGTH, - HTTP2_HEADER_EXPECT + HTTP2_HEADER_EXPECT, + HTTP2_HEADER_STATUS } } = http2 @@ -1365,9 +1366,7 @@ function _resume (client, sync) { return } - if ((socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) || - (client[kHTTP2Session] && client[kHTTP2Session].destroyed)) { - // TODO(HTTP/2): what if exceeds max concurrent streams or can't accept new + if ((socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking])) { return } @@ -1777,7 +1776,7 @@ function writeH2 (client, session, request) { } stream.on('response', headers => { - if (request.onHeaders(Number(headers[':status']), headers, stream.resume.bind(stream), '') === false) { + if (request.onHeaders(Number(headers[HTTP2_HEADER_STATUS]), headers, stream.resume.bind(stream), '') === false) { stream.pause() } }) diff --git a/lib/core/request.js b/lib/core/request.js index 4f92a08d927..0fb2eb75e57 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -158,6 +158,8 @@ class Request { this.expectContinue = expectContinue != null ? expectContinue : false + this[kRawRequestHeaders] = null + if (Array.isArray(headers)) { if (headers.length % 2 !== 0) { throw new InvalidArgumentError('headers array must be even') diff --git a/test/http2.js b/test/http2.js index 3c9068f2d4d..62f0dd34d29 100644 --- a/test/http2.js +++ b/test/http2.js @@ -464,7 +464,7 @@ test('Dispatcher#destroy', async t => { } }) - t.plan(3) + t.plan(4) t.teardown(server.close.bind(server)) promises.push( @@ -497,6 +497,16 @@ test('Dispatcher#destroy', async t => { }) ) + promises.push( + client.request({ + path: '/', + method: 'GET', + headers: { + 'x-my-header': 'foo' + } + }) + ) + await client.destroy() const results = await Promise.allSettled(promises) @@ -504,6 +514,7 @@ test('Dispatcher#destroy', async t => { t.equal(results[0].status, 'rejected') t.equal(results[1].status, 'rejected') t.equal(results[2].status, 'rejected') + t.equal(results[3].status, 'rejected') }) test('Should handle h2 request with body (string or buffer) - dispatch', t => {