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

Fixed the issue of @listeners getting nil io #1120

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/puma/binder.rb
Expand Up @@ -105,7 +105,7 @@ def parse(binds, logger)
io = add_tcp_listener uri.host, uri.port, opt, bak
end

@listeners << [str, io]
@listeners << [str, io] if io
when "unix"
path = "#{uri.host}#{uri.path}".gsub("%20", " ")

Expand Down Expand Up @@ -209,7 +209,7 @@ def parse(binds, logger)
io = add_ssl_listener uri.host, uri.port, ctx
end

@listeners << [str, io]
@listeners << [str, io] if io
else
logger.error "Invalid URI: #{str}"
end
Expand Down
34 changes: 34 additions & 0 deletions test/test_binder.rb
@@ -0,0 +1,34 @@
require "rbconfig"
require 'test/unit'
require 'testhelp'

require 'puma/binder'
require 'puma/events'

class TestBinder < Test::Unit::TestCase

def setup
@events = Puma::Events.new(STDOUT, STDERR)
@binder = Puma::Binder.new(@events)
end

def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
omit_on_jruby

@binder.parse(["tcp://localhost:10001"], @events)

assert_equal [], @binder.listeners
end

def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses
omit_on_jruby

key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__

@binder.parse(["ssl://localhost:10002?key=#{key}&cert=#{cert}"], @events)

assert_equal [], @binder.listeners
end

end
8 changes: 8 additions & 0 deletions test/testhelp.rb
Expand Up @@ -9,6 +9,7 @@
require 'stringio'

require 'puma'
require 'puma/detect'

# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
Expand Down Expand Up @@ -41,3 +42,10 @@ def run(*args)
end
end
Test::Unit::TestCase.prepend TimeoutEveryTestCase

module OmitTestsBasedOnRubyEngine
def omit_on_jruby
omit "Omitted on JRuby" if Puma.jruby?
end
end
Test::Unit::TestCase.prepend OmitTestsBasedOnRubyEngine