-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathhttp2-http2.test.js
59 lines (47 loc) · 1.36 KB
/
http2-http2.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
const h2url = require('h2url')
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const fs = require('node:fs')
const path = require('node:path')
const certs = {
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
}
t.test('http2 -> http2', async (t) => {
const instance = Fastify({
http2: true,
https: certs
})
t.teardown(instance.close.bind(instance))
const target = Fastify({
http2: true
})
target.get('/', (_request, reply) => {
t.pass('request proxied')
reply.code(404).header('x-my-header', 'hello!').send({
hello: 'world'
})
})
instance.get('/', (_request, reply) => {
reply.from()
})
t.teardown(target.close.bind(target))
await target.listen({ port: 0 })
instance.register(From, {
base: `http://localhost:${target.server.address().port}`,
http2: true,
rejectUnauthorized: false
})
await instance.listen({ port: 0 })
const { headers, body } = await h2url.concat({
url: `https://localhost:${instance.server.address().port}`
})
t.equal(headers[':status'], 404)
t.equal(headers['x-my-header'], 'hello!')
t.match(headers['content-type'], /application\/json/)
t.same(JSON.parse(body), { hello: 'world' })
instance.close()
target.close()
})