lib/ramaze/current/request.rb in manveru-ramaze-2008.07 vs lib/ramaze/current/request.rb in manveru-ramaze-2008.08

- old
+ new

@@ -9,11 +9,11 @@ # and provide some convinient methods for our own use. class Request < ::Rack::Request class << self - # get the current request out of Thread.current[:request] + # get the current request out of STATE[:request] # # You can call this from everywhere with Ramaze::Request.current def current() Current.request end end @@ -31,11 +31,15 @@ def request_uri env['REQUEST_URI'] || path_info end def ip - env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_ADDR'] + if addr = env['HTTP_X_FORWARDED_FOR'] + addr.split(',').last.strip + else + env['REMOTE_ADDR'] + end end # Request is from a local network? # Checks both IPv4 and IPv6 @@ -46,10 +50,9 @@ # -- # Mongrel somehow puts together multiple IPs when proxy is involved. # ++ def local_net?(address = ip) - address = address.to_s.split(',').first addr = IPAddr.new(address) LOCAL.find{|range| range.include?(addr) } rescue ArgumentError => ex raise ArgumentError, ex unless ex.message == 'invalid address' end