lib/firewall_constraint.rb in firewall_constraint-0.1.2 vs lib/firewall_constraint.rb in firewall_constraint-0.1.3

- old
+ new

@@ -11,12 +11,16 @@ @ips = !ips.empty? ? ips : [YAML.load_file(Rails.root.join('config','firewall_constraint.yml'))[Rails.env]].flatten.compact end end + def requestor_ip(request) + request.env["HTTP_X_FORWARDED_FOR"] ? request.env["HTTP_X_FORWARDED_FOR"].split(/, /).first : request.remote_ip + end + def matches?(request) return true if parsed_ips.empty? - client_ip = IPAddress::parse(request.env["HTTP_X_FORWARDED_FOR"] ? request.env["HTTP_X_FORWARDED_FOR"] : request.remote_ip) + client_ip = IPAddress::parse requestor_ip(request) parsed_ips.each do |ip| begin return true if ip.include?(client_ip) rescue NoMethodError => nme end