aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-08-13 17:34:20 -0300
committerXavier Noria <fxn@hashref.com>2010-08-14 13:17:31 +0200
commit4c2bbe9a1abfefacda71764ad583c0a302b1fc4e (patch)
tree7dd706c236d08fca6852e8571e08dcca791f2c7b /actionpack/lib/action_dispatch/http
parente8ffe7d6b6302de789a612be0ad98349b10daa9c (diff)
downloadrails-4c2bbe9a1abfefacda71764ad583c0a302b1fc4e.tar.gz
rails-4c2bbe9a1abfefacda71764ad583c0a302b1fc4e.tar.bz2
rails-4c2bbe9a1abfefacda71764ad583c0a302b1fc4e.zip
Moves local_request? to require.local?
[#5361 state:committed]
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index fd23b1df79..5606d6abfe 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -15,6 +15,8 @@ module ActionDispatch
include ActionDispatch::Http::Upload
include ActionDispatch::Http::URL
+ LOCALHOST = [/^127\.0\.0\.\d{1,3}$/, "::1", /^0:0:0:0:0:0:0:1(%.*)?$/].freeze
+
%w[ AUTH_TYPE GATEWAY_INTERFACE
PATH_TRANSLATED REMOTE_HOST
REMOTE_IDENT REMOTE_USER REMOTE_ADDR
@@ -231,5 +233,10 @@ module ActionDispatch
@env['X_HTTP_AUTHORIZATION'] ||
@env['REDIRECT_X_HTTP_AUTHORIZATION']
end
+
+ # True if the request came from localhost, 127.0.0.1.
+ def local?
+ LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
+ end
end
end