Skip to content

Commit

Permalink
properly handle pseudo-headers in fetch (nodejs#2422)
Browse files Browse the repository at this point in the history
properly handle pseudo-headers in fetch
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent add731b commit 036355d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ async function httpNetworkFetch (
location = val
}

headers.append(key, val)
headers[kHeadersList].append(key, val)
}
} else {
const keys = Object.keys(headersList)
Expand All @@ -2016,7 +2016,7 @@ async function httpNetworkFetch (
location = val
}

headers.append(key, val)
headers[kHeadersList].append(key, val)
}
}

Expand Down Expand Up @@ -2120,7 +2120,7 @@ async function httpNetworkFetch (
const key = headersList[n + 0].toString('latin1')
const val = headersList[n + 1].toString('latin1')

headers.append(key, val)
headers[kHeadersList].append(key, val)
}

resolve({
Expand Down
11 changes: 6 additions & 5 deletions test/fetch/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ const { once } = require('node:events')
const { Blob } = require('node:buffer')
const { Readable } = require('node:stream')

const { test, plan, skip } = require('tap')
const { test, plan } = require('tap')
const pem = require('https-pem')

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

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

skip('Skip H2 test due to pseudo-header issue.')
process.exit(0)

plan(6)

test('[Fetch] Issue#2311', async t => {
Expand Down Expand Up @@ -87,7 +84,7 @@ test('[Fetch] Simple GET with h2', async t => {
stream.end(expectedRequestBody)
})

t.plan(4)
t.plan(5)

server.listen()
await once(server, 'listening')
Expand Down Expand Up @@ -120,6 +117,10 @@ test('[Fetch] Simple GET with h2', async t => {
t.equal(responseBody, expectedRequestBody)
t.equal(response.headers.get('x-method'), 'GET')
t.equal(response.headers.get('x-custom-h2'), 'foo')
// https://github.com/nodejs/undici/issues/2415
t.throws(() => {
response.headers.get(':status')
}, TypeError)

// See https://fetch.spec.whatwg.org/#concept-response-status-message
t.equal(response.statusText, '')
Expand Down

0 comments on commit 036355d

Please sign in to comment.