Skip to content

Commit

Permalink
Merge branch 'http2' into http2-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 authored Jul 17, 2023
2 parents 93696a2 + d6e0219 commit 2e49522
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ class Request {
const keys = Object.keys(headers)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
processHeader(this, key, headers[key])
const headerValue = headers[key]
processHeader(this, key, headerValue)
this[kRawRequestHeaders] = {
[key]: headerValue
}
}
this[kRawRequestHeaders] = headers
} else if (headers != null) {
Expand Down
47 changes: 46 additions & 1 deletion test/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const pem = require('https-pem')

const { Client } = require('..')

plan(15)
plan(16)

test('Should support H2 connection', async t => {
const body = []
Expand Down Expand Up @@ -60,6 +60,51 @@ test('Should support H2 connection', async t => {
t.equal(Buffer.concat(body).toString('utf8'), 'hello h2!')
})

test('Should support H2 connection (headers as array)', async t => {
const body = []
const server = createSecureServer(pem)

server.on('stream', (stream, headers) => {
t.equal(headers['x-my-header'], 'foo')
t.equal(headers[':method'], 'GET')
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
}
})

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

const response = await client.request({
path: '/',
method: 'GET',
headers: ['x-my-header', 'foo']
})

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)
Expand Down

0 comments on commit 2e49522

Please sign in to comment.