diff --git a/lib/puma/dsl.rb b/lib/puma/dsl.rb index eca8fe71f8..e2e142246c 100644 --- a/lib/puma/dsl.rb +++ b/lib/puma/dsl.rb @@ -118,6 +118,10 @@ def bind(url) @options[:binds] << url end + def clear_binds! + @options[:binds] = [] + end + # Define the TCP port to bind to. Use +bind+ for more advanced options. # def port(port, host=nil) diff --git a/lib/rack/handler/puma.rb b/lib/rack/handler/puma.rb index ef1a2a7f6a..83b757c24a 100644 --- a/lib/rack/handler/puma.rb +++ b/lib/rack/handler/puma.rb @@ -84,6 +84,8 @@ def self.valid_options end private def self.set_host_port_to_config(host, port, config) + config.clear_binds! if host || port + if host && (host[0,1] == '.' || host[0,1] == '/') config.bind "unix://#{host}" elsif host && host =~ /^ssl:\/\// diff --git a/test/test_rack_handler.rb b/test/test_rack_handler.rb index 73809cb12d..fa9e75a638 100644 --- a/test/test_rack_handler.rb +++ b/test/test_rack_handler.rb @@ -153,6 +153,16 @@ def test_config_wins_over_default end end + def test_user_port_wins_over_default_when_user_supplied_is_blank + user_port = 5001 + @options[:user_supplied_options] = [] + @options[:Port] = user_port + conf = Rack::Handler::Puma.config(->{}, @options) + conf.load + + assert_equal ["tcp://0.0.0.0:#{user_port}"], conf.options[:binds] + end + def test_user_port_wins_over_default user_port = 5001 @options[:Port] = user_port