Sha256: 41ca1d952f0f19d26c7497fb37c93ba86a476820550e93e03cd8575896fbe6ef

Contents?: true

Size: 1.57 KB

Versions: 6809

Compression:

Stored size: 1.57 KB

Contents

require 'rack/typhoeus/middleware/params_decoder/helper'

module Rack
  module Typhoeus
    module Middleware

      # 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
      class ParamsDecoder
        include ParamsDecoder::Helper

        def initialize(app)
          @app = app
        end

        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

        # Persist params change in environment. Extracted from:
        # https://github.com/rack/rack/blob/master/lib/rack/request.rb#L243
        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
      end
    end
  end
end

Version data entries

6,809 entries across 6,806 versions & 27 rubygems

Version Path
cybrid_api_id_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_organization_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_bank_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_organization_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_id_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_bank_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_id_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_organization_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-1.15.17 vendor/bundle/ruby/3.1.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_bank_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_organization_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_id_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_organization_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_bank_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_id_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_organization_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_bank_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_id_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_bank_ruby-0.123.111 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb
cybrid_api_organization_ruby-0.123.111 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/rack/typhoeus/middleware/params_decoder.rb