Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ internals.Info = class {
this.received = received;
this.referrer = req.headers.referrer || req.headers.referer || '';
this.host = host;
this.hostname = host.split(':')[0];
this.hostname = /(.*?)(?::\d+)?$/.exec(host)[1];
Comment thread
Marsup marked this conversation as resolved.
Outdated
this.id = `${received}:${request._core.info.id}:${request._core._counter()}`;

this._remoteAddress = null;
Expand Down
30 changes: 30 additions & 0 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ describe('Request.Generator', () => {

describe('Request', () => {

it('sets host and hostname', async () => {

const server = Hapi.server();

const handler = (request) => {

return [request.info.host, request.info.hostname].join('|');
};

server.route({ method: 'GET', path: '/', handler });

const res1 = await server.inject({ url: '/', headers: { host: 'host' } });
expect(res1.payload).to.equal('host|host');

const res2 = await server.inject({ url: '/', headers: { host: 'host:123' } });
expect(res2.payload).to.equal('host:123|host');

const res3 = await server.inject({ url: '/', headers: { host: '127.0.0.1' } });
expect(res3.payload).to.equal('127.0.0.1|127.0.0.1');

const res4 = await server.inject({ url: '/', headers: { host: '127.0.0.1:123' } });
expect(res4.payload).to.equal('127.0.0.1:123|127.0.0.1');

const res5 = await server.inject({ url: '/', headers: { host: '[::1]' } });
expect(res5.payload).to.equal('[::1]|[::1]');

const res6 = await server.inject({ url: '/', headers: { host: '[::1]:123' } });
expect(res6.payload).to.equal('[::1]:123|[::1]');
});

it('sets client address (default)', async (flags) => {

const server = Hapi.server();
Expand Down