Skip to content

request.info.host - Host header wrong in server.inject #2824

Description

@ldesplat

Bell tests break because since hapijs/shot#43, Shot always sends a Host header except that when it does not know the Host header itself or from the uri, then it guesses localhost. The problem is that in some cases this may be wrong as the port could be different than 80 or 443.

Bell anticipated no host headers and when request.info.host was empty then it would use the request.connection.info.host along with request.connection.info.port to set the oauth_callback url in some circumstances.

I understand this is a very minor issue. This is a Hapi issue, because Shot has no way of knowing what the right port is and is doing its best shot at guessing it :)

Now, there are easy workarounds (send Host header from server.inject, give full url, ...). I can easily fix Bell tests with this new behavior. The maximum impact I can see this having is if people are logging those inject requests and the Host header is wrong. I know before they did not get the Host header which was perhaps annoying but at least not wrong.

Here is a simple test that reproduces the issue:

it('reproduces behavior', function (done) {

        var server = new Hapi.Server();
        server.connection({ host: 'localhost', port: 2080 });
        server.route({
            method: 'GET',
            path: '/test',
            handler: function (request, reply) {

                reply(request.info.host || request.connection.info.host + ':' + request.connection.info.port);
            }
        });

        server.inject('/test', function (res) {

            // Hapi 10 returns 'localhost'
            expect(res.payload).to.equal('localhost:2080');
            done();
        });
    });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions