diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-24 14:57:05 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-24 14:57:05 -0700 |
commit | c4c5918b688da1ca00be34e3c66fcc5ca78500b1 (patch) | |
tree | d14c0487b86f3f03ced98bf30157ee05aaed2ff6 /actionpack/lib/action_dispatch | |
parent | ec9c237acc1f140df464e824d9e28c78c96837e7 (diff) | |
download | rails-c4c5918b688da1ca00be34e3c66fcc5ca78500b1.tar.gz rails-c4c5918b688da1ca00be34e3c66fcc5ca78500b1.tar.bz2 rails-c4c5918b688da1ca00be34e3c66fcc5ca78500b1.zip |
stop using `@env` in the GET / POST methods
I want to implement this with something besides `@env` in the future, so
lets stop directly referencing it.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/request.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 6 |
2 files changed, 11 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 4748a54550..b9fc703fe2 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -323,7 +323,9 @@ module ActionDispatch # Override Rack's GET method to support indifferent access def GET - @env["action_dispatch.request.query_parameters"] ||= normalize_encode_params(super || {}) + get_header("action_dispatch.request.query_parameters") do |k| + set_header k, normalize_encode_params(super || {}) + end rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise ActionController::BadRequest.new(:query, e) end @@ -331,7 +333,9 @@ module ActionDispatch # Override Rack's POST method to support indifferent access def POST - @env["action_dispatch.request.request_parameters"] ||= normalize_encode_params(super || {}) + get_header("action_dispatch.request.request_parameters") do |k| + self.request_parameters = normalize_encode_params(super || {}) + end rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise ActionController::BadRequest.new(:request, e) end @@ -352,6 +356,7 @@ module ActionDispatch end def request_parameters=(params) + raise if params.nil? set_header("action_dispatch.request.request_parameters".freeze, params) end diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index 402ad778fa..9cde9c9b98 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -37,7 +37,9 @@ module ActionDispatch def call(env) request = Request.new(env) - request.request_parameters = parse_formatted_parameters(request, @parsers) + parse_formatted_parameters(request, @parsers) do |params| + request.request_parameters = params + end @app.call(env) end @@ -48,7 +50,7 @@ module ActionDispatch strategy = parsers.fetch(request.content_mime_type) { return nil } - strategy.call(request.raw_post) + yield strategy.call(request.raw_post) rescue => e # JSON or Ruby code block errors logger(request).debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}" |