1 | 'use strict'
|
2 |
|
3 | const t = require('tap')
|
4 | const test = t.test
|
5 | const fs = require('fs')
|
6 | const path = require('path')
|
7 | const Fastify = require('../..')
|
8 | const h2url = require('h2url')
|
9 | const msg = { hello: 'world' }
|
10 |
|
11 | var fastify
|
12 | try {
|
13 | fastify = Fastify({
|
14 | http2: true,
|
15 | https: {
|
16 | key: fs.readFileSync(path.join(__dirname, '..', 'https', 'fastify.key')),
|
17 | cert: fs.readFileSync(path.join(__dirname, '..', 'https', 'fastify.cert'))
|
18 | }
|
19 | })
|
20 | t.pass('Key/cert successfully loaded')
|
21 | } catch (e) {
|
22 | t.fail('Key/cert loading failed', e)
|
23 | }
|
24 |
|
25 | fastify.get('/', function (req, reply) {
|
26 | reply.code(200).send(msg)
|
27 | })
|
28 |
|
29 | fastify.listen(0, err => {
|
30 | t.error(err)
|
31 | fastify.server.unref()
|
32 |
|
33 | test('https get request', async (t) => {
|
34 | t.plan(3)
|
35 |
|
36 | const url = `https://localhost:${fastify.server.address().port}`
|
37 | const res = await h2url.concat({ url })
|
38 |
|
39 | t.strictEqual(res.headers[':status'], 200)
|
40 | t.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length)
|
41 | t.deepEqual(JSON.parse(res.body), msg)
|
42 | })
|
43 | })
|