|
| 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