Skip to content

Commit

Permalink
http2: fix req.hostname not set (#2113)
Browse files Browse the repository at this point in the history
* http2: fix req.hostname not set

* Update lib/route.js

Co-Authored-By: Matteo Collina <matteo.collina@gmail.com>

Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
mohd-akram and mcollina committed Feb 24, 2020
1 parent 6f79a90 commit 093947b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/route.js
Expand Up @@ -307,7 +307,7 @@ function buildRouting (options) {

req.id = req.headers[requestIdHeader] || genReqId(req)
req.originalUrl = req.url
var hostname = req.headers.host
var hostname = req.headers.host || req.headers[':authority']
var ip = req.connection.remoteAddress
var ips

Expand Down
15 changes: 15 additions & 0 deletions test/http2/plain.js
Expand Up @@ -20,6 +20,10 @@ fastify.get('/', function (req, reply) {
reply.code(200).send(msg)
})

fastify.get('/hostname', function (req, reply) {
reply.code(200).send(req.hostname)
})

fastify.listen(0, err => {
t.error(err)
fastify.server.unref()
Expand All @@ -35,4 +39,15 @@ fastify.listen(0, err => {

t.deepEqual(JSON.parse(res.body), msg)
})

test('http hostname', async (t) => {
t.plan(1)

const hostname = `localhost:${fastify.server.address().port}`

const url = `http://${hostname}/hostname`
const res = await h2url.concat({ url })

t.strictEqual(res.body, hostname)
})
})

0 comments on commit 093947b

Please sign in to comment.