From 4e2852a4870677cab12e61795a1c500058f8f111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 19 Jan 2010 12:17:52 +0100 Subject: Do not send rack.input or any other rack information to AD listeners. --- .../lib/action_dispatch/middleware/notifications.rb | 19 +++++++++++++------ actionpack/lib/action_dispatch/railties/subscriber.rb | 4 ++-- actionpack/test/dispatch/subscriber_test.rb | 5 ++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/notifications.rb b/actionpack/lib/action_dispatch/middleware/notifications.rb index 01d2cbb435..c3776d53a8 100644 --- a/actionpack/lib/action_dispatch/middleware/notifications.rb +++ b/actionpack/lib/action_dispatch/middleware/notifications.rb @@ -8,17 +8,24 @@ module ActionDispatch @app = app end - def call(stack_env) - env = stack_env.dup - ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", :env => env) + def call(env) + payload = retrieve_payload_from_env(env) + ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", payload) - ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", :env => env) do - @app.call(stack_env) + ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", payload) do + @app.call(env) end rescue Exception => exception ActiveSupport::Notifications.instrument('action_dispatch.exception', - :env => stack_env, :exception => exception) + :env => env, :exception => exception) raise exception end + + protected + + # Remove any rack related constants from the env, like rack.input. + def retrieve_payload_from_env(env) + Hash[:env => env.except(*env.keys.select { |k| k.to_s.index("rack.") == 0 })] + end end end \ No newline at end of file diff --git a/actionpack/lib/action_dispatch/railties/subscriber.rb b/actionpack/lib/action_dispatch/railties/subscriber.rb index c08a844c6a..cdb1162eac 100644 --- a/actionpack/lib/action_dispatch/railties/subscriber.rb +++ b/actionpack/lib/action_dispatch/railties/subscriber.rb @@ -5,8 +5,8 @@ module ActionDispatch request = Request.new(event.payload[:env]) path = request.request_uri.inspect rescue "unknown" - info "\n\nProcessing #{path} to #{request.formats.join(', ')} " << - "(for #{request.remote_ip} at #{event.time.to_s(:db)}) [#{request.method.to_s.upcase}]" + info "\n\nStarted #{request.method.to_s.upcase} #{path} " << + "for #{request.remote_ip} at #{event.time.to_s(:db)}" end def logger diff --git a/actionpack/test/dispatch/subscriber_test.rb b/actionpack/test/dispatch/subscriber_test.rb index a7f1a2659a..3096c132e7 100644 --- a/actionpack/test/dispatch/subscriber_test.rb +++ b/actionpack/test/dispatch/subscriber_test.rb @@ -78,9 +78,8 @@ module DispatcherSubscriberTest log = @logger.logged(:info).first assert_equal 1, @logger.logged(:info).size - assert_match %r{^Processing "/" to text/html}, log - assert_match %r{\(for 127\.0\.0\.1}, log - assert_match %r{\[GET\]}, log + assert_match %r{^Started GET "/"}, log + assert_match %r{for 127\.0\.0\.1}, log end def test_subscriber_has_its_logged_flushed_after_request -- cgit v1.2.3