From 9fc65acee7e8aa5ee187a8591ac02c6c47eefa5a Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Tue, 20 Jan 2015 10:34:14 -0800 Subject: [PATCH] Set a default REMOTE_ADDR to avoid using peeraddr on unix sockets. Fixes #583 --- lib/puma/binder.rb | 8 ++++++++ lib/puma/server.rb | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/puma/binder.rb b/lib/puma/binder.rb index 5931fe2e..a622bab3 100644 --- a/lib/puma/binder.rb +++ b/lib/puma/binder.rb @@ -288,6 +288,10 @@ module Puma File.chmod mode, path end + env = @proto_env.dup + env[REMOTE_ADDR] = "127.0.0.1" + @envs[s] = env + s end @@ -301,6 +305,10 @@ module Puma end @ios << s + env = @proto_env.dup + env[REMOTE_ADDR] = "127.0.0.1" + @envs[s] = env + s end diff --git a/lib/puma/server.rb b/lib/puma/server.rb index dd7d1f2b..b731bd3d 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -456,12 +456,14 @@ module Puma # intermediary acting on behalf of the actual source client." # - addr = client.peeraddr.last + unless env.key?(REMOTE_ADDR) + addr = client.peeraddr.last - # Set unix socket addrs to localhost - addr = "127.0.0.1" if addr.empty? + # Set unix socket addrs to localhost + addr = "127.0.0.1" if addr.empty? - env[REMOTE_ADDR] = addr + env[REMOTE_ADDR] = addr + end end def default_server_port(env)