From 04d403f17be31ec398a17dcce74d8338dc84dcd9 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sat, 26 Dec 2009 21:29:24 +0700 Subject: [PATCH] Make local_request? to returns true when facing ::1 IPv6 address --- actionpack/lib/action_controller/rescue.rb | 4 ++-- actionpack/test/controller/rescue_test.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb index 242c8da..58bbf0c 100644 --- a/actionpack/lib/action_controller/rescue.rb +++ b/actionpack/lib/action_controller/rescue.rb @@ -15,7 +15,7 @@ module ActionController #:nodoc: # behavior is achieved by overriding the rescue_action_in_public # and rescue_action_locally methods. module Rescue - LOCALHOST = '127.0.0.1'.freeze + LOCALHOST = ['127.0.0.1', '::1'].freeze DEFAULT_RESCUE_RESPONSE = :internal_server_error DEFAULT_RESCUE_RESPONSES = { @@ -122,7 +122,7 @@ module ActionController #:nodoc: # method if you wish to redefine the meaning of a local request to # include remote IP addresses or other criteria. def local_request? #:doc: - request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST + LOCALHOST.any?{ |local_ip| request.remote_addr == local_ip && request.remote_ip == local_ip } end # Render detailed diagnostics for unhandled exceptions rescued from diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 5709f37..7531f94 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -285,6 +285,9 @@ class RescueControllerTest < ActionController::TestCase with_remote_addr '127.0.0.1' do assert @controller.send(:local_request?) end + with_remote_addr '::1' do + assert @controller.send(:local_request?) + end end def test_local_request_when_remote_addr_isnt_locahost @@ -292,6 +295,9 @@ class RescueControllerTest < ActionController::TestCase with_remote_addr '1.2.3.4' do assert !@controller.send(:local_request?) end + with_remote_addr '2002::102:304' do + assert !@controller.send(:local_request?) + end end def test_rescue_responses -- 1.6.4.2