Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: fix req.hostname not set #2113

Merged
merged 2 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
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[':authority'] || req.headers.host
mohd-akram marked this conversation as resolved.
Show resolved Hide resolved
var ip = req.connection.remoteAddress
var ips

Expand Down
15 changes: 15 additions & 0 deletions test/http2/plain.js
Original file line number Diff line number Diff line change
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)
})
})