lib/rack/contrib/access.rb in rack-contrib-2.2.0 vs lib/rack/contrib/access.rb in rack-contrib-2.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require "ipaddr"
module Rack
##
@@ -46,13 +48,13 @@
[host, location, match, ipmasks]
}.sort_by { |(h, l, m, a)| [h ? -h.size : (-1.0 / 0.0), -l.size] } # Longest path first
end
def call(env)
- @original_request = Request.new(env)
+ request = Request.new(env)
ipmasks = ipmasks_for_path(env)
- return forbidden! unless ip_authorized?(ipmasks)
+ return forbidden! unless ip_authorized?(request, ipmasks)
status, headers, body = @app.call(env)
[status, headers, body]
end
def ipmasks_for_path(env)
@@ -71,14 +73,14 @@
def forbidden!
[403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
end
- def ip_authorized?(ipmasks)
+ def ip_authorized?(request, ipmasks)
return true if ipmasks.nil?
ipmasks.any? do |ip_mask|
- ip_mask.include?(IPAddr.new(@original_request.ip))
+ ip_mask.include?(IPAddr.new(request.ip))
end
end
end
end