/
http2-target-crash.js
55 lines (44 loc) · 1.14 KB
/
http2-target-crash.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
'use strict'
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('../..')
const got = require('got')
test('http -> http2 crash', async (t) => {
const instance = Fastify()
t.tearDown(instance.close.bind(instance))
const target = Fastify({
http2: true
})
target.get('/', (request, reply) => {
t.pass('request proxied')
reply.code(200).send({
hello: 'world'
})
})
instance.get('/', (request, reply) => {
reply.from()
})
t.tearDown(target.close.bind(target))
await target.listen(0)
instance.register(From, {
base: `http://localhost:${target.server.address().port}`,
http2: true
})
await instance.listen(0)
try {
await target.close()
await got(`http://localhost:${instance.server.address().port}`, {
rejectUnauthorized: false
})
} catch (err) {
t.equal(err.response.statusCode, 503)
t.match(err.response.headers['content-type'], /application\/json/)
t.deepEqual(JSON.parse(err.response.body), {
statusCode: 503,
error: 'Service Unavailable',
message: 'Service Unavailable'
})
return
}
t.fail()
})