Class: XForwardedIPSelector

Inherits:
Object
  • Object
show all
Includes:
IPSelectorInterface
Defined in:
lib/ipinfo-rails/ip_selector/xforwarded_ip_selector.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ XForwardedIPSelector

Returns a new instance of XForwardedIPSelector.



7
8
9
# File 'lib/ipinfo-rails/ip_selector/xforwarded_ip_selector.rb', line 7

def initialize(request)
    @request = request
end

Instance Method Details

#get_ipObject



11
12
13
14
15
16
17
18
# File 'lib/ipinfo-rails/ip_selector/xforwarded_ip_selector.rb', line 11

def get_ip()
    x_forwarded = @request.env['HTTP_X_FORWARDED_FOR']
    if !x_forwarded || x_forwarded.empty?
        return @request.ip
    else
        return x_forwarded.split(',' , -1)[0]
    end
end