Skip to content

Commit 8cecb47

Browse files
committed
reduced localhost check to two method calls
1 parent c512730 commit 8cecb47

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

actionpack/lib/action_dispatch/http/request.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class Request < Rack::Request
1717
include ActionDispatch::Http::Upload
1818
include ActionDispatch::Http::URL
1919

20-
LOCALHOST = [/^127\.0\.0\.\d{1,3}$/, "::1", /^0:0:0:0:0:0:0:1(%.*)?$/].freeze
20+
LOCALHOST = Regexp.union [/^127\.0\.0\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/]
21+
2122
ENV_METHODS = %w[ AUTH_TYPE GATEWAY_INTERFACE
2223
PATH_TRANSLATED REMOTE_HOST
2324
REMOTE_IDENT REMOTE_USER REMOTE_ADDR
@@ -250,7 +251,7 @@ def authorization
250251

251252
# True if the request came from localhost, 127.0.0.1.
252253
def local?
253-
LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
254+
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
254255
end
255256

256257
private

0 commit comments

Comments
 (0)