Skip to content

Commit 0931d93

Browse files
authored
do not strip TE headers if trailing (#443)
1 parent 1dbfe61 commit 0931d93

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

lib/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ function stripHttp1ConnectionHeaders (headers) {
4242
case 'connection':
4343
case 'upgrade':
4444
case 'http2-settings':
45-
case 'te':
4645
case 'transfer-encoding':
4746
case 'proxy-connection':
4847
case 'keep-alive':
4948
case 'host':
5049
break
50+
case 'te':
51+
// see illegal connection specific header handling in Node.js
52+
if (headers['te'] === 'trailers') {
53+
dest[header] = headers[header]
54+
}
55+
break
5156
default:
5257
dest[header] = headers[header]
5358
break
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict'
2+
const h2url = require('h2url')
3+
const t = require('node:test')
4+
const Fastify = require('fastify')
5+
const From = require('..')
6+
const fs = require('node:fs')
7+
const path = require('node:path')
8+
const certs = {
9+
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
10+
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
11+
}
12+
13+
t.test('do not strip te header if set to trailing', async (t) => {
14+
const instance = Fastify({
15+
http2: true,
16+
https: certs
17+
})
18+
19+
t.after(() => instance.close())
20+
21+
const target = Fastify({
22+
http2: true
23+
})
24+
25+
target.get('/', (request, reply) => {
26+
t.assert.strictEqual(request.headers['te'], 'trailers')
27+
28+
reply.send({
29+
hello: 'world'
30+
})
31+
})
32+
33+
instance.get('/', (_request, reply) => {
34+
reply.from()
35+
})
36+
37+
t.after(() => target.close())
38+
39+
await target.listen({ port: 0 })
40+
41+
instance.register(From, {
42+
base: `http://localhost:${target.server.address().port}`,
43+
http2: true,
44+
rejectUnauthorized: false
45+
})
46+
47+
await instance.listen({ port: 0 })
48+
49+
const { headers } = await h2url.concat({
50+
url: `https://localhost:${instance.server.address().port}`,
51+
headers: {
52+
te: 'trailers'
53+
}
54+
})
55+
56+
t.assert.strictEqual(headers[':status'], 200)
57+
58+
instance.close()
59+
target.close()
60+
})

0 commit comments

Comments
 (0)