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

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

Closed
ldesplat opened this issue Oct 5, 2015 · 0 comments
Closed

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

ldesplat opened this issue Oct 5, 2015 · 0 comments
Assignees
Labels
Milestone

Comments

@ldesplat
Copy link
Contributor

@ldesplat ldesplat commented Oct 5, 2015

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();
        });
    });
@ldesplat ldesplat changed the title request.info.host - Host header wrong in Shot request.info.host - Host header wrong in server.inject Oct 5, 2015
@hueniverse hueniverse added the bug label Oct 5, 2015
@hueniverse hueniverse self-assigned this Oct 5, 2015
@hueniverse hueniverse added this to the 10.4.0 milestone Oct 5, 2015
@hueniverse hueniverse closed this in 21983e0 Oct 5, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants