Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve performance for filtered parameters and add tests.

  • Loading branch information...
commit a55f2de0c5baae589b1730df1e4068f0cd1474ce 1 parent 1afb56f
@josevalim josevalim authored
View
5 actionpack/lib/action_controller/base.rb
@@ -194,7 +194,6 @@ def self.without_modules(*modules)
Caching,
MimeResponds,
ImplicitRender,
- ParamsWrapper,
Cookies,
Flash,
@@ -215,6 +214,10 @@ def self.without_modules(*modules)
# all the methods properly.
Instrumentation,
+ # Params wrapper should come before instrumentation so they are
+ # properly showed in logs
+ ParamsWrapper,
+
# The same with rescue, append it at the end to wrap as much as possible.
Rescue
]
View
2  actionpack/lib/action_controller/metal/instrumentation.rb
@@ -14,7 +14,7 @@ module Instrumentation
attr_internal :view_runtime
- def process_action(action, *args)
+ def process_action(*args)
raw_payload = {
:controller => self.class.name,
:action => self.action_name,
View
5 actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -178,14 +178,13 @@ def _set_wrapper_defaults(options, model=nil)
def process_action(*args)
if _wrapper_enabled?
wrapped_hash = { _wrapper_key => request.request_parameters.slice(*_wrapped_keys) }
- wrapped_filtered_hash = { _wrapper_key => request.filtered_parameters.slice(*_wrapped_keys) }
# This will make the wrapped hash accessible from controller and view
request.parameters.merge! wrapped_hash
request.request_parameters.merge! wrapped_hash
# This will make the wrapped hash displayed in the log file
- request.filtered_parameters.merge! wrapped_filtered_hash
+ request.clear_filtered_parameters
end
super
end
@@ -215,7 +214,7 @@ def _wrapper_formats
# Checks if we should perform parameters wrapping.
def _wrapper_enabled?
ref = request.content_mime_type.try(:ref)
- _wrapper_formats.any? { |format| format == ref } && !request.request_parameters[_wrapper_key]
+ _wrapper_formats.include?(ref) && !request.request_parameters[_wrapper_key]
end
end
end
View
5 actionpack/lib/action_dispatch/http/filter_parameters.rb
@@ -33,6 +33,11 @@ def filtered_parameters
@filtered_parameters ||= parameter_filter.filter(parameters)
end
+ # Clear any filtered parameters forcing them to be filtered again.
+ def clear_filtered_parameters
+ @filtered_parameters = nil
+ end
+
# Return a hash of request.env with all sensitive data replaced.
def filtered_env
@filtered_env ||= env_filter.filter(@env)
View
11 actionpack/test/controller/log_subscriber_test.rb
@@ -4,6 +4,8 @@
module Another
class LogSubscribersController < ActionController::Base
+ wrap_parameters :person, :only => :name, :format => :json
+
def show
render :nothing => true
end
@@ -95,6 +97,15 @@ def test_process_action_with_parameters
assert_equal 'Parameters: {"id"=>"10"}', logs[1]
end
+ def test_process_action_with_wrapped_parameters
+ @request.env['CONTENT_TYPE'] = 'application/json'
+ post :show, :id => '10', :name => 'jose'
+ wait
+
+ assert_equal 3, logs.size
+ assert_match '"person"=>{"name"=>"jose"}', logs[1]
+ end
+
def test_process_action_with_view_runtime
get :show
wait
Please sign in to comment.
Something went wrong with that request. Please try again.