class Rack::Typhoeus::Middleware::ParamsDecoder
This Rack middleware takes care of the proper deserialization of the nested params encoded by Typhoeus.
@example Require the railtie when using Rails.
require 'typhoeus/railtie'
@example Include the middleware for Rack based applications.
use Rack::Typhoeus::Middleware::ParamsDecoder
@example Use the helper directly. Not recommended as b/c the interface might change.
require 'rack/typhoeus/middleware/params_decoder/helper' include Rack::Typhoeus::Middleware::ParamsDecoder::Helper decode!(params)
@author Dwayne Macgowan @since 0.5.4
Public Class Methods
new(app)
click to toggle source
# File lib/rack/typhoeus/middleware/params_decoder.rb, line 26 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/typhoeus/middleware/params_decoder.rb, line 30 def call(env) req = Rack::Request.new(env) decode(req.params).each_pair { |k, v| update_params req, k, v } @app.call(env) end
Private Instance Methods
update_params(req, k, v)
click to toggle source
Persist params change in environment. Extracted from: github.com/rack/rack/blob/master/lib/rack/request.rb#L243
# File lib/rack/typhoeus/middleware/params_decoder.rb, line 40 def update_params(req, k, v) found = false if req.GET.has_key?(k) found = true req.GET[k] = v end if req.POST.has_key?(k) found = true req.POST[k] = v end unless found req.GET[k] = v end end