diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-04-21 11:14:53 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-04-21 11:16:38 -0700 |
commit | 79080e97c0ef1863c1e80a9ddf30c69323af1ca7 (patch) | |
tree | 1285a6d91ab86827f51615990eef364e238e761b /lib | |
parent | 588577cc4852f9dce1bd011451399ce96c00023c (diff) | |
download | unicorn-79080e97c0ef1863c1e80a9ddf30c69323af1ca7.tar.gz |
This removes the #unicorn_peeraddr methods from TCPSocket and UNIXSocket core classes. Instead, just move that logic into the only place it needs to be used in HttpRequest.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn/http_request.rb | 20 | ||||
-rw-r--r-- | lib/unicorn/socket.rb | 13 |
2 files changed, 11 insertions, 22 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index d170505..9be3b11 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -55,6 +55,16 @@ module Unicorn # This does minimal exception trapping and it is up to the caller # to handle any socket errors (e.g. user aborted upload). def read(socket) + # From http://www.ietf.org/rfc/rfc3875: + # "Script authors should be aware that the REMOTE_ADDR and + # REMOTE_HOST meta-variables (see sections 4.1.8 and 4.1.9) + # may not identify the ultimate source of the request. They + # identify the client for the immediate request to the server; + # that client may be a proxy, gateway, or other intermediary + # acting on behalf of the actual source client." + @params[Const::REMOTE_ADDR] = + TCPSocket === socket ? socket.peeraddr.last : '127.0.0.1' + # short circuit the common case with small GET requests first @parser.execute(@params, read_socket(socket)) and return handle_body(socket) @@ -70,7 +80,7 @@ module Unicorn rescue HttpParserError => e @logger.error "HTTP parse error, malformed request " \ "(#{@params[Const::HTTP_X_FORWARDED_FOR] || - socket.unicorn_peeraddr}): #{e.inspect}" + @params[Const::REMOTE_ADDR]}): #{e.inspect}" @logger.error "REQUEST DATA: #{data.inspect}\n---\n" \ "PARAMS: #{@params.inspect}\n---\n" raise e @@ -120,14 +130,6 @@ module Unicorn # over the HTTP response. # @params["unicorn.client"] = socket - # From http://www.ietf.org/rfc/rfc3875: - # "Script authors should be aware that the REMOTE_ADDR and - # REMOTE_HOST meta-variables (see sections 4.1.8 and 4.1.9) - # may not identify the ultimate source of the request. They - # identify the client for the immediate request to the server; - # that client may be a proxy, gateway, or other intermediary - # acting on behalf of the actual source client." - @params[Const::REMOTE_ADDR] = socket.unicorn_peeraddr @params[Const::RACK_INPUT] = @body @params.update(DEF_PARAMS) end diff --git a/lib/unicorn/socket.rb b/lib/unicorn/socket.rb index 5a3bfd7..850ad85 100644 --- a/lib/unicorn/socket.rb +++ b/lib/unicorn/socket.rb @@ -1,18 +1,5 @@ require 'socket' -class UNIXSocket - UNICORN_PEERADDR = '127.0.0.1'.freeze - def unicorn_peeraddr - UNICORN_PEERADDR - end -end - -class TCPSocket - def unicorn_peeraddr - peeraddr.last - end -end - module Unicorn module SocketHelper include Socket::Constants |