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

registerWebInterface() redirect ignores X-Forwarded-Port header #1490

Closed
mintyfresh opened this issue May 12, 2016 · 3 comments
Closed

registerWebInterface() redirect ignores X-Forwarded-Port header #1490

mintyfresh opened this issue May 12, 2016 · 3 comments

Comments

@mintyfresh
Copy link
Contributor

Minimal case to reproduce,

@path("/users")
class Users {
    void index() {
        render!"index.dt";
    }
}

shared static this() {
    URLRouter router = new URLRouter;

    // . . .

    router.registerWebInterface(new Users);
}

Requests made to /users are redirected to /users/, however, the redirect includes the port number the vibe app accepted the request on. This is problematic for environments where the internal port number (which vibed is bound to) does not match the external port number (which requests arrive on). For example if the app listens on port 5000, but incoming requests are actually accepted on port 80.

I've set up a Heroku app that demonstrates this behavior. Note that it is running on a free dyno, and may take a while to spin up.

Works correctly: http://testrig.herokuapp.com/users/
Problem redirect: http://testrig.herokuapp.com/users
(May redirect to something like: http://testrig.herokuapp.com:48669/users/)

In the case of Heroku, this is particularly problematic as there is no control over what the internal port number is. It is assigned (via environment variable) whenever the app is deployed, and is usually different every time.

@s-ludwig
Copy link
Member

Currently the server expects the "X-Forwarded-Host" header to be set by the proxy server - if that is given, it will ignore the local port. This works for simple setups, but should definitely be made customizable in the future. Does Heroku set any similar headers, or can it be made to?

@mintyfresh
Copy link
Contributor Author

mintyfresh commented May 12, 2016

It appears Heroku does not set the X-Forwarded-Host header, but instead all of these,
https://devcenter.heroku.com/articles/http-routing#heroku-headers

Other major HTTP servers appear to support these, but this is probably the cause of the issue.

EDIT: Looking at vibe/http/server.d, it appears to check for X-Forwarded-Host and disregard related headers if it's not present.

mintyfresh pushed a commit to mintyfresh/vibe.d that referenced this issue May 12, 2016
mintyfresh pushed a commit to mintyfresh/vibe.d that referenced this issue May 12, 2016
mintyfresh pushed a commit to mintyfresh/vibe.d that referenced this issue May 12, 2016
mintyfresh pushed a commit to mintyfresh/vibe.d that referenced this issue May 12, 2016
mintyfresh pushed a commit to mintyfresh/vibe.d that referenced this issue May 12, 2016
@mintyfresh mintyfresh changed the title registerWebInterface() redirects include internal port number. registerWebInterface() redirects ignores X-Forwarded-Port header May 16, 2016
@mintyfresh mintyfresh changed the title registerWebInterface() redirects ignores X-Forwarded-Port header registerWebInterface() redirect ignores X-Forwarded-Port header May 16, 2016
s-ludwig added a commit that referenced this issue May 18, 2016
#1490 Add support for X-Forwarded-Port header.
@mintyfresh
Copy link
Contributor Author

Resolved by #1491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants