Sha256: 41ca1d952f0f19d26c7497fb37c93ba86a476820550e93e03cd8575896fbe6ef

Contents?: true

Size: 1.57 KB

Versions: 6916

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,916 entries across 6,913 versions & 28 rubygems

Version Path
ory-client-0.0.1.alpha111 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha110 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha109 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
avalara_sdk-2.4.26 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha108 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-oathkeeper-client-0.38.23.beta1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-oathkeeper-client-0.38.22.beta1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha107 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-hydra-client-1.11.7 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha106 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-hydra-client-1.11.6 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-keto-client-0.8.0.alpha1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha105 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha104 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha103 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-hydra-client-1.11.5 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-1.30.0 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha101 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha100 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-hydra-client-1.11.4 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb