From 0babf16288833a4406c874dbba1f8c1a89cbc9fe Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sat, 26 Dec 2009 21:41:30 +0700 Subject: [PATCH] Make local_request? to returns true when facing ::1 IPv6 address --- .../action_dispatch/middleware/show_exceptions.rb | 4 +- actionpack/test/dispatch/show_exceptions_test.rb | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 4ebc8a2..451b2c4 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -3,7 +3,7 @@ require 'action_dispatch/http/request' module ActionDispatch class ShowExceptions - LOCALHOST = '127.0.0.1'.freeze + LOCALHOST = ['127.0.0.1', '::1'].freeze RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates') @@ -98,7 +98,7 @@ module ActionDispatch # 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) diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 9f6a937..def86c8 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -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 -- 1.6.4.2