Skip to content

Commit

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

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
sikachu authored and josevalim committed Jan 18, 2010
1 parent c50609c commit 6012e57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/rescue.rb
Expand Up @@ -15,7 +15,7 @@ module ActionController #:nodoc:
# behavior is achieved by overriding the <tt>rescue_action_in_public</tt>
# and <tt>rescue_action_locally</tt> 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 = {
Expand Down Expand Up @@ -122,7 +122,7 @@ def render_optional_error_file(status_code)
# 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
Expand Down
10 changes: 8 additions & 2 deletions actionpack/test/controller/rescue_test.rb
Expand Up @@ -281,17 +281,23 @@ def test_rescue_action_locally
end

def test_local_request_when_remote_addr_is_localhost
@controller.expects(:request).returns(@request).at_least_once
@controller.expects(:request).returns(@request).at_least(4)
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
@controller.expects(:request).returns(@request)
@controller.expects(:request).returns(@request).at_least(4)
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
Expand Down

0 comments on commit 6012e57

Please sign in to comment.