diff options
| author | Gibheer <gibheer@gmail.com> | 2014-03-05 09:42:49 +0100 | 
|---|---|---|
| committer | Gibheer <gibheer@gmail.com> | 2014-03-05 09:44:06 +0100 | 
| commit | 4aab135bc6fffb0b13979e240479c24a3f553b06 (patch) | |
| tree | 9a1d0810b8e534def30c6a2d84da2d6d3536078c /lib | |
| parent | 3876754ab4b139bf8387d9f37e0502008743783e (diff) | |
add x-forwarded-for header to the client
This adds the way to find out the actual ip of the client machine, even
if it is hidden behind a local reverse proxy.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/zero/request/client.rb | 15 | 
1 files changed, 14 insertions, 1 deletions
| diff --git a/lib/zero/request/client.rb b/lib/zero/request/client.rb index 2a27cb7..eba4d7a 100644 --- a/lib/zero/request/client.rb +++ b/lib/zero/request/client.rb @@ -4,6 +4,8 @@ module Zero      class Client        # the key for the ip of the client        KEY_REMOTE_ADDR = 'REMOTE_ADDR' +      # in proxy setups, this is the real address of the client +      KEY_FORWARDED_FOR = 'X_FORWARDED_FOR'        # the key for the hostname        KEY_REMOTE_HOST = 'REMOTE_HOST'        # the key for the user agent @@ -12,7 +14,10 @@ module Zero        # creates a new client with the data of the request environment        # @param environment a hash representation of the request        def initialize(environment) -        @address    = environment[KEY_REMOTE_ADDR] +        # extract the two possible ips +        @forwarded_for  = environment[KEY_FORWARDED_FOR] +        @remote_address = environment[KEY_REMOTE_ADDR] +        @address    = forwarded_for || remote_address          @hostname   = environment[KEY_REMOTE_HOST]          @user_agent = environment[KEY_USER_AGENT]        end @@ -26,6 +31,14 @@ module Zero        # the user agent of the client        # @return [String] the user agent of the client        attr_reader :user_agent + +      # get the forwarded address, set in proxy setups +      # @return [String] the address set in KEY_FORWARDED_FOR header +      attr_reader :forwarded_for + +      # get the remote address given by KEY_REMOTE_ADDR +      # @return [String] the remote address defined in KEY_REMOTE_ADDR header +      attr_reader :remote_address      end    end  end | 
