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

server.rb - refactor code using @options[:remote_address] #2742

Merged
merged 1 commit into from Dec 12, 2021
Merged
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
27 changes: 10 additions & 17 deletions lib/puma/server.rb
Expand Up @@ -315,16 +315,15 @@ def handle_servers
queue_requests = @queue_requests
drain = @options[:drain_on_shutdown] ? 0 : nil

remote_addr_value = nil
remote_addr_header = nil

case @options[:remote_address]
addr_send_name, addr_value = case @options[:remote_address]
when :value
remote_addr_value = @options[:remote_address_value]
[:peerip=, @options[:remote_address_value]]
when :header
remote_addr_header = @options[:remote_address_header]
[:remote_addr_header=, @options[:remote_address_header]]
when :proxy_protocol
remote_addr_proxy_protocol = @options[:remote_address_proxy_protocol]
[:expect_proxy_proto=, @options[:remote_address_proxy_protocol]]
else
[nil, nil]
end

while @status == :run || (drain && shutting_down?)
Expand All @@ -344,16 +343,10 @@ def handle_servers
next
end
drain += 1 if shutting_down?
client = Client.new io, @binder.env(sock)
client.listener = sock
if remote_addr_value
client.peerip = remote_addr_value
elsif remote_addr_header
client.remote_addr_header = remote_addr_header
elsif remote_addr_proxy_protocol
client.expect_proxy_proto = remote_addr_proxy_protocol
end
pool << client
pool << Client.new(io, @binder.env(sock)).tap { |c|
c.listener = sock
c.send(addr_send_name, addr_value) if addr_value
}
end
end
rescue IOError, Errno::EBADF
Expand Down