Skip to content

Commit

Permalink
remove http2 status pseudo header from headers
Browse files Browse the repository at this point in the history
Co-authored-by: tsctx <91457664+tsctx@users.noreply.github.com>

fixup
  • Loading branch information
KhafraDev committed Nov 15, 2023
1 parent b37bbf7 commit 58adb11
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,9 @@ function writeH2 (client, session, request) {
++h2State.openStreams

stream.once('response', headers => {
if (request.onHeaders(Number(headers[HTTP2_HEADER_STATUS]), headers, stream.resume.bind(stream), '') === false) {
const { [HTTP2_HEADER_STATUS]: statusCode, ...realHeaders } = headers

if (request.onHeaders(Number(statusCode), realHeaders, stream.resume.bind(stream), '') === false) {
stream.pause()
}
})
Expand Down
42 changes: 40 additions & 2 deletions test/fetch/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const { Readable } = require('node:stream')
const { test, plan } = require('tap')
const pem = require('https-pem')

const { Client, fetch } = require('../..')
const { Client, fetch, Headers } = require('../..')

const nodeVersion = Number(process.version.split('v')[1].split('.')[0])

plan(6)
plan(7)

test('[Fetch] Issue#2311', async t => {
const expectedBody = 'hello from client!'
Expand Down Expand Up @@ -375,3 +375,41 @@ test(
t.equal(Buffer.concat(requestChunks).toString('utf-8'), expectedBody)
}
)

test('Issue#2415', async (t) => {
t.plan(1)
const server = createSecureServer(pem)

server.on('stream', async (stream, headers) => {
stream.respond({
':status': 200
})
stream.end('test')
})

server.listen()
await once(server, 'listening')

const client = new Client(`https://localhost:${server.address().port}`, {
connect: {
rejectUnauthorized: false
},
allowH2: true
})

const response = await fetch(
`https://localhost:${server.address().port}/`,
// Needs to be passed to disable the reject unauthorized
{
method: 'GET',
dispatcher: client
}
)

await response.text()

t.teardown(server.close.bind(server))
t.teardown(client.close.bind(client))

t.doesNotThrow(() => new Headers(response.headers))
})

0 comments on commit 58adb11

Please sign in to comment.