Skip to content

Commit

Permalink
refactor: adjust accordingly to review
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Jul 19, 2023
1 parent f6246f0 commit 149137d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
}
})
Expand Down
2 changes: 2 additions & 0 deletions lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 12 additions & 1 deletion test/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ test('Dispatcher#destroy', async t => {
}
})

t.plan(3)
t.plan(4)
t.teardown(server.close.bind(server))

promises.push(
Expand Down Expand Up @@ -497,13 +497,24 @@ 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)

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 => {
Expand Down

0 comments on commit 149137d

Please sign in to comment.