/ puma Public
Rack handler should use provided default host #1700
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
This issue is somewhat tricky. When Rails is booted via
rails serverthere are two types of configuration options passed, ones specified directly by a user like
rails s -p 3001will always "win".
For any other config that is not explicitly passed in, puma will consider it a "default". For example when you run
rails s(without -p) then the default port will be 3000.
There is one other way to configure puma though, and that is via a config file:
This is the order of precedence for configuration
This fallback mechanism works well except in the case of calling
config/puma.rbfile. To understand look at the old method definition:
portmethod gets called, even if the user did not specify a
Configuration::DefaultTCPHostwill be used, which is a problem for local development because it defaults to
0.0.0.0. SO about 0.0.0.0 versus localhost.
In this case, while a user did directly specify a port, they did not specify a host, so you would expect the
rails sdefaults passed in to take affect.
To make Puma respect that the host coming from
rails shas more precedence than it's own default host, we must introduce the ability to set and retrieve a default_host value.
This is then used in the rack handler so when
rails spasses in
:Host => "localhost"then it is used instead of reverting to
The issue with #1699 is the test was wrong, it would have failed if a config file was present with a