Skip to content

Commit

Permalink
Fix served_url printed when using Puma & Rack 3
Browse files Browse the repository at this point in the history
This `#use_puma?` check was [introduced][1] because Rails could
potentially display the wrong server URL in development if another host
or port is configured in `config/puma.rb`.

However, in Rack 3 the the name of the server class changed from
`Rack::Handler::Puma` to `Rackup::Handler::Puma`, which means that the
served_url is being logged again.

This commit fixes the check to accept either version of the class.
Additionally, puma was updated in Gemfile.lock because Puma 6.0.x prints
a deprecation warning about Rack::Handler that's fixed in 6.1.0.

[1]: 29648ff
  • Loading branch information
skipkayhil committed Aug 18, 2023
1 parent 1e824aa commit 2d61a20
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ GEM
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nio4r (2.5.9)
nokogiri (1.15.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
Expand All @@ -373,7 +373,7 @@ GEM
psych (5.1.0)
stringio
public_suffix (5.0.1)
puma (6.0.2)
puma (6.3.0)
nio4r (~> 2.0)
queue_classic (4.0.0)
pg (>= 1.1, < 2.0)
Expand Down
4 changes: 2 additions & 2 deletions railties/lib/rails/commands/server/server_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def log_to_stdout
end

def use_puma?
server.to_s == "Rack::Handler::Puma"
server.to_s.end_with?("Handler::Puma")
end
end

Expand All @@ -96,7 +96,7 @@ class ServerCommand < Base # :nodoc:

RACK_HANDLER_GEMS = %w(cgi webrick scgi thin puma unicorn falcon)
# Hard-coding a bunch of handlers here as we don't have a public way of
# querying them from the Rack::Handler registry.
# querying them from the Rackup::Handler registry.
RACK_HANDLERS = RACK_HANDLER_GEMS + %w(fastcgi lsws)
RECOMMENDED_SERVER = "puma"

Expand Down
6 changes: 6 additions & 0 deletions railties/test/commands/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ def test_served_url
assert_equal "http://127.0.0.1:4567", server.served_url
end

def test_served_url_when_server_prints_it
args = %w(-u puma -b 127.0.0.1 -p 4567)
server = Rails::Server.new(parse_arguments(args))
assert_nil server.served_url
end

private
def run_command(*args)
build_app
Expand Down

0 comments on commit 2d61a20

Please sign in to comment.