From b04d465d65f896290d36538181d91dd264d10575 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 28 Mar 2010 17:35:10 -0700 Subject: cleanup: avoid redundant REMOTE_ADDR logic 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. --- lib/rainbows/base.rb | 2 +- lib/rainbows/const.rb | 1 - lib/rainbows/ev_core.rb | 2 +- lib/rainbows/fiber/rev.rb | 2 +- lib/rainbows/revactor.rb | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/rainbows') 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 -- cgit v1.2.3-24-ge0c7