Skip to content

Commit

Permalink
Make local_request? to returns true when facing ::1 IPv6 address [#3257
Browse files Browse the repository at this point in the history
… status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
sikachu authored and josevalim committed Jan 17, 2010
1 parent a0dc6cc commit eb67532
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/middleware/show_exceptions.rb
Expand Up @@ -20,7 +20,7 @@ module ActionDispatch
# * :exception - The exception raised;
#
class ShowExceptions
LOCALHOST = '127.0.0.1'.freeze
LOCALHOST = ['127.0.0.1', '::1'].freeze

RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')

Expand Down Expand Up @@ -118,7 +118,7 @@ def rescue_action_in_public(exception)

# True if the request came from localhost, 127.0.0.1.
def local_request?(request)
request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST
LOCALHOST.any?{ |local_ip| request.remote_addr == local_ip && request.remote_ip == local_ip }
end

def status_code(exception)
Expand Down
22 changes: 12 additions & 10 deletions actionpack/test/dispatch/show_exceptions_test.rb
Expand Up @@ -53,19 +53,21 @@ class ShowExceptionsTest < ActionController::IntegrationTest

test "rescue locally from a local request" do
@app = ProductionApp
self.remote_addr = '127.0.0.1'
['127.0.0.1', '::1'].each do |ip_address|
self.remote_addr = ip_address

get "/"
assert_response 500
assert_match /puke/, body
get "/"
assert_response 500
assert_match /puke/, body

get "/not_found"
assert_response 404
assert_match /#{ActionController::UnknownAction.name}/, body
get "/not_found"
assert_response 404
assert_match /#{ActionController::UnknownAction.name}/, body

get "/method_not_allowed"
assert_response 405
assert_match /ActionController::MethodNotAllowed/, body
get "/method_not_allowed"
assert_response 405
assert_match /ActionController::MethodNotAllowed/, body
end
end

test "localize public rescue message" do
Expand Down

0 comments on commit eb67532

Please sign in to comment.