Skip to content

Commit

Permalink
Simplify Runner#start_control URL parsing (#2111)
Browse files Browse the repository at this point in the history
* Simplify Runner#start_control URL parsing
Reuse logic from Binder#parse.

* Parameterize log message
  • Loading branch information
wjordan committed Feb 20, 2020
1 parent 4f8a85f commit a948c16
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -17,6 +17,7 @@
* Refactor
* Remove unused loader argument from Plugin initializer (#2095)
* Simplify `Configuration.random_token` and remove insecure fallback (#2102)
* Simplify `Runner#start_control` URL parsing (#2111)

## 4.3.1 and 3.12.2 / 2019-12-05

Expand Down
6 changes: 3 additions & 3 deletions lib/puma/binder.rb
Expand Up @@ -86,7 +86,7 @@ def import_from_env
end
end

def parse(binds, logger)
def parse(binds, logger, log_msg = 'Listening')
binds.each do |str|
uri = URI.parse str
case uri.scheme
Expand All @@ -113,7 +113,7 @@ def parse(binds, logger)
i.local_address.ip_unpack.join(':')
end

logger.log "* Listening on tcp://#{addr}"
logger.log "* #{log_msg} on tcp://#{addr}"
end
end

Expand Down Expand Up @@ -149,7 +149,7 @@ def parse(binds, logger)
end

io = add_unix_listener path, umask, mode, backlog
logger.log "* Listening on #{str}"
logger.log "* #{log_msg} on #{str}"
end

@listeners << [str, io]
Expand Down
22 changes: 1 addition & 21 deletions lib/puma/runner.rb
Expand Up @@ -52,8 +52,6 @@ def start_control

require 'puma/app/status'

uri = URI.parse str

if token = @options[:control_auth_token]
token = nil if token.empty? || token == 'none'
end
Expand All @@ -64,25 +62,7 @@ def start_control
control.min_threads = 0
control.max_threads = 1

case uri.scheme
when "ssl"
log "* Starting control server on #{str}"
params = Util.parse_query uri.query
ctx = MiniSSL::ContextBuilder.new(params, @events).context

control.add_ssl_listener uri.host, uri.port, ctx
when "tcp"
log "* Starting control server on #{str}"
control.add_tcp_listener uri.host, uri.port
when "unix"
log "* Starting control server on #{str}"
path = "#{uri.host}#{uri.path}"
mask = @options[:control_url_umask]

control.add_unix_listener path, mask
else
error "Invalid control URI: #{str}"
end
control.binder.parse [str], self, 'Starting control server'

control.run
@control = control
Expand Down

0 comments on commit a948c16

Please sign in to comment.