about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-03-28 17:35:10 -0700
committerEric Wong <normalperson@yhbt.net>2010-03-28 17:35:10 -0700
commitb04d465d65f896290d36538181d91dd264d10575 (patch)
tree6e00e4ec3421c07713da4d5678c231a5f2b19d73
parent12a4c53a47bb0c7bef5e2df732fa02532a969a54 (diff)
downloadrainbows-b04d465d65f896290d36538181d91dd264d10575.tar.gz
Every concurrency model does this the same way.

This removes the Rainbows::Const::LOCALHOST constant and
may break some existing apps that rely on it.
-rw-r--r--lib/rainbows.rb7
-rw-r--r--lib/rainbows/base.rb2
-rw-r--r--lib/rainbows/const.rb1
-rw-r--r--lib/rainbows/ev_core.rb2
-rw-r--r--lib/rainbows/fiber/rev.rb2
-rw-r--r--lib/rainbows/revactor.rb2
6 files changed, 11 insertions, 5 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index 5c8ee94..50db8a8 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -73,6 +73,13 @@ module Rainbows
       rv
     rescue Errno::EAGAIN, Errno::ECONNABORTED
     end
+
+    # returns a string representing the address of the given client +io+
+    # For local UNIX domain sockets, this will return a string referred
+    # to by the (non-frozen) Unicorn::HttpRequest::LOCALHOST constant.
+    def addr(io)
+      TCPSocket == io ? io.peeraddr.last : Unicorn::HttpRequest::LOCALHOST
+    end
   end
 
   # configures \Rainbows! with a given concurrency model to +use+ and
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index a29a5bb..a9314ee 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -36,7 +36,7 @@ module Rainbows
       hp = HttpParser.new
       env = {}
       alive = true
-      remote_addr = TCPSocket === client ? client.peeraddr.last : LOCALHOST
+      remote_addr = Rainbows.addr(client)
 
       begin # loop
         while ! hp.headers(env, buf)
diff --git a/lib/rainbows/const.rb b/lib/rainbows/const.rb
index 4250866..bc6d700 100644
--- a/lib/rainbows/const.rb
+++ b/lib/rainbows/const.rb
@@ -17,7 +17,6 @@ module Rainbows
 
     CONN_CLOSE = "Connection: close\r\n"
     CONN_ALIVE = "Connection: keep-alive\r\n"
-    LOCALHOST = Unicorn::HttpRequest::LOCALHOST
 
     # client IO object that supports reading and writing directly
     # without filtering it through the HTTP chunk parser.
diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb
index 3d02b8a..682bdd6 100644
--- a/lib/rainbows/ev_core.rb
+++ b/lib/rainbows/ev_core.rb
@@ -14,7 +14,7 @@ module Rainbows
     ASYNC_CLOSE = "async.close".freeze
 
     def post_init
-      @remote_addr = ::TCPSocket === @_io ? @_io.peeraddr.last : LOCALHOST
+      @remote_addr = Rainbows.addr(@_io)
       @env = {}
       @hp = HttpParser.new
       @state = :headers # [ :body [ :trailers ] ] :app_call :close
diff --git a/lib/rainbows/fiber/rev.rb b/lib/rainbows/fiber/rev.rb
index bd9638f..a733103 100644
--- a/lib/rainbows/fiber/rev.rb
+++ b/lib/rainbows/fiber/rev.rb
@@ -80,7 +80,7 @@ module Rainbows::Fiber
         hp = HttpParser.new
         env = {}
         alive = true
-        remote_addr = TCPSocket === io ? io.peeraddr.last : LOCALHOST
+        remote_addr = Rainbows.addr(io)
 
         begin # loop
           buf << (client.read_timeout or return) until hp.headers(env, buf)
diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb
index ab65184..ed08f2c 100644
--- a/lib/rainbows/revactor.rb
+++ b/lib/rainbows/revactor.rb
@@ -37,7 +37,7 @@ module Rainbows
         rd_args << RD_ARGS
         client.remote_addr
       else
-        LOCALHOST
+        Unicorn::HttpRequest::LOCALHOST
       end
       buf = client.read(*rd_args)
       hp = HttpParser.new