Skip to content

Commit

Permalink
Allow alternative schemes in Binder (puma#3302 )
Browse files Browse the repository at this point in the history
  • Loading branch information
tomurb committed Mar 18, 2024
1 parent 87fd289 commit 9e61153
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/puma/binder.rb
Expand Up @@ -141,7 +141,14 @@ def synthesize_binds_from_activated_fs(binds, only_matching)
end
end

def before_parse(&block)
@before_parse ||= []
@before_parse << block if block
@before_parse
end

def parse(binds, log_writer = nil, log_msg = 'Listening')
before_parse.each(&:call)
log_writer ||= @log_writer
binds.each do |str|
uri = URI.parse str
Expand Down
14 changes: 14 additions & 0 deletions test/test_binder.rb
Expand Up @@ -79,6 +79,20 @@ def test_synthesize_binds_from_activated_fds_complex_binds
assert_equal expected, result
end

def test_runs_before_parse_hooks
mock = Minitest::Mock.new
proc = -> { mock.call }

@binder.before_parse &proc

mock.expect(:call, nil)

@binder.parse ["tcp://localhost:0"]

mock.verify
assert_equal @binder.instance_variable_get(:@before_parse), [proc]
end

def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
@binder.parse ["tcp://localhost:0"], @log_writer

Expand Down

0 comments on commit 9e61153

Please sign in to comment.