Skip to content

Commit

Permalink
reduced localhost check to two method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Feb 29, 2012
1 parent c512730 commit 8cecb47
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -17,7 +17,8 @@ class Request < Rack::Request
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
LOCALHOST = Regexp.union [/^127\.0\.0\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/]

ENV_METHODS = %w[ AUTH_TYPE GATEWAY_INTERFACE
PATH_TRANSLATED REMOTE_HOST
REMOTE_IDENT REMOTE_USER REMOTE_ADDR
Expand Down Expand Up @@ -250,7 +251,7 @@ def authorization

# 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 }
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
end

private
Expand Down

0 comments on commit 8cecb47

Please sign in to comment.