Module: Rack::Request::Helpers

Defined in:
lib/rack-custom-proxies.rb

Instance Method Summary collapse

Instance Method Details

#trusted_proxy?(ip) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack-custom-proxies.rb', line 20

def trusted_proxy?(ip)
  Rack::Request.trusted_proxies.each do |tp|
    begin
      return true if tp.include?(ip)
    rescue IPAddr::InvalidAddressError
      # If we get an invalid address, we can just ignore it
      # and check the next one
    end
  end
  false
end