aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r--actionpack/lib/action_controller/metal/filter_parameter_logging.rb71
-rw-r--r--actionpack/lib/action_controller/metal/helpers.rb2
-rw-r--r--actionpack/lib/action_controller/metal/instrumentation.rb35
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb43
4 files changed, 46 insertions, 105 deletions
diff --git a/actionpack/lib/action_controller/metal/filter_parameter_logging.rb b/actionpack/lib/action_controller/metal/filter_parameter_logging.rb
deleted file mode 100644
index 0b1e1ee6ab..0000000000
--- a/actionpack/lib/action_controller/metal/filter_parameter_logging.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-module ActionController
- module FilterParameterLogging
- extend ActiveSupport::Concern
-
- INTERNAL_PARAMS = %w(controller action format _method only_path)
-
- module ClassMethods
- # Replace sensitive parameter data from the request log.
- # Filters parameters that have any of the arguments as a substring.
- # Looks in all subhashes of the param hash for keys to filter.
- # If a block is given, each key and value of the parameter hash and all
- # subhashes is passed to it, the value or key
- # can be replaced using String#replace or similar method.
- #
- # Examples:
- #
- # filter_parameter_logging :password
- # => replaces the value to all keys matching /password/i with "[FILTERED]"
- #
- # filter_parameter_logging :foo, "bar"
- # => replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
- #
- # filter_parameter_logging { |k,v| v.reverse! if k =~ /secret/i }
- # => reverses the value to all keys matching /secret/i
- #
- # filter_parameter_logging(:foo, "bar") { |k,v| v.reverse! if k =~ /secret/i }
- # => reverses the value to all keys matching /secret/i, and
- # replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
- def filter_parameter_logging(*filter_words, &block)
- raise "You must filter at least one word from logging" if filter_words.empty?
-
- parameter_filter = Regexp.new(filter_words.join('|'), true)
-
- define_method(:filter_parameters) do |original_params|
- filtered_params = {}
-
- original_params.each do |key, value|
- if key =~ parameter_filter
- value = '[FILTERED]'
- elsif value.is_a?(Hash)
- value = filter_parameters(value)
- elsif value.is_a?(Array)
- value = value.map { |item| filter_parameters(item) }
- elsif block_given?
- key = key.dup
- value = value.dup if value.duplicable?
- yield key, value
- end
-
- filtered_params[key] = value
- end
-
- filtered_params.except!(*INTERNAL_PARAMS)
- end
- protected :filter_parameters
- end
- end
-
- protected
-
- def append_info_to_payload(payload)
- super
- payload[:params] = filter_parameters(request.params)
- end
-
- def filter_parameters(params)
- params.dup.except!(*INTERNAL_PARAMS)
- end
-
- end
-end
diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb
index d0402e5bad..cdd14560e1 100644
--- a/actionpack/lib/action_controller/metal/helpers.rb
+++ b/actionpack/lib/action_controller/metal/helpers.rb
@@ -100,7 +100,7 @@ module ActionController
module_path = module_name.underscore
helper module_path
rescue MissingSourceFile => e
- raise e unless e.is_missing? "#{module_path}_helper"
+ raise e unless e.is_missing? "helpers/#{module_path}_helper"
rescue NameError => e
raise e unless e.missing_name? "#{module_name}Helper"
end
diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb
index 876f778751..7f9a7c068b 100644
--- a/actionpack/lib/action_controller/metal/instrumentation.rb
+++ b/actionpack/lib/action_controller/metal/instrumentation.rb
@@ -9,35 +9,34 @@ module ActionController
module Instrumentation
extend ActiveSupport::Concern
- included do
- include AbstractController::Logger
- end
+ include AbstractController::Logger
attr_internal :view_runtime
def process_action(action, *args)
- ActiveSupport::Notifications.instrument("action_controller.process_action") do |payload|
+ raw_payload = {
+ :controller => self.class.name,
+ :action => self.action_name,
+ :params => request.filtered_parameters,
+ :formats => request.formats.map(&:to_sym)
+ }
+
+ ActiveSupport::Notifications.instrument("action_controller.start_processing", raw_payload.dup)
+
+ ActiveSupport::Notifications.instrument("action_controller.process_action", raw_payload) do |payload|
result = super
- payload[:controller] = self.class.name
- payload[:action] = self.action_name
- payload[:status] = response.status
+ payload[:status] = response.status
append_info_to_payload(payload)
result
end
end
- def render(*args, &block)
- if logger
- render_output = nil
-
- self.view_runtime = cleanup_view_runtime do
- Benchmark.ms { render_output = super }
- end
-
- render_output
- else
- super
+ def render(*args)
+ render_output = nil
+ self.view_runtime = cleanup_view_runtime do
+ Benchmark.ms { render_output = super }
end
+ render_output
end
def send_file(path, options={})
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 74e50bb032..72e2bbd00e 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -12,9 +12,10 @@ module ActionController
super
end
- def render(options)
- super
- self.content_type ||= options[:_template].mime_type.to_s
+ def render(*args)
+ args << {} unless args.last.is_a?(Hash)
+ super(*args)
+ self.content_type ||= args.last[:_template].mime_type.to_s
response_body
end
@@ -24,18 +25,6 @@ module ActionController
end
private
- def _prefix
- controller_path
- end
-
- def _determine_template(options)
- if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
- options[:_template_name] ||= options[:action]
- options[:_prefix] = _prefix
- end
-
- super
- end
def _render_partial(options)
options[:partial] = action_name if options[:partial] == true
@@ -53,5 +42,29 @@ module ActionController
self.content_type = content_type if content_type
self.headers["Location"] = url_for(location) if location
end
+
+ def _normalize_options(action=nil, options={}, &blk)
+ case action
+ when NilClass
+ when Hash
+ options = super(action.delete(:action), action)
+ when String, Symbol
+ options = super
+ else
+ options.merge! :partial => action
+ end
+
+ if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
+ options[:_template_name] ||= options[:action]
+ options[:_prefix] = _prefix
+ end
+
+ if options[:status]
+ options[:status] = Rack::Utils.status_code(options[:status])
+ end
+
+ options[:update] = blk if block_given?
+ options
+ end
end
end