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

Add config option to manually define Rack url scheme #2569

Closed
tarragon opened this issue Mar 9, 2021 · 3 comments · Fixed by #2586
Closed

Add config option to manually define Rack url scheme #2569

tarragon opened this issue Mar 9, 2021 · 3 comments · Fixed by #2586

Comments

@tarragon
Copy link

tarragon commented Mar 9, 2021

We need to run Puma behind a service that is unfortunately not passing down HTTP_X_FORWARDED headers. We also need to run Puma on a port other than port 443 and not in SSL mode, while the frontend service handles the SSL.

This has caused a problem within Puma where redirects generated by Rails (notably on session create) use http rather than https and this is confusing clients and the frontend service.

The only way I can find in Puma itself to set Rack's url scheme is with this line in lib/puma/request.rb:

env[RACK_URL_SCHEME] = default_server_port(env) == PORT_443 ? HTTPS : HTTP

Following the thread, default_server_port checks if Puma is running in SSL mode, then checks if the X_FORWARDED headers are there, returning PORT_443 in this case, otherwise PORT_80. To work around this I have monkey patched default_server_port to return PORT_443 in our environment regardless.

It would be great to be able to more explicitly control the Rack url scheme, and I suggest that the port assumptions here could do with refactoring for environments where Puma is running on a custom port (neither 443 or 80).

If there's some other way to achieve what I'm trying to achieve or if I've missed some configuration option, please let me know.

@MSP-Greg
Copy link
Member

Makes sense, as the frontend really defines this. I think adding a config option, and, if it's not set, the current setting (as shown above) will be used. I'll post a PR soon...

@tarragon
Copy link
Author

Hey there, I notice this has a contrib-wanted label now, is there anything I can do to help?

@MSP-Greg
Copy link
Member

I'm adjusting some things in PR #2586, which adds the feature... Thanks.

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

Successfully merging a pull request may close this issue.

3 participants