Sha256: 41ca1d952f0f19d26c7497fb37c93ba86a476820550e93e03cd8575896fbe6ef

Contents?: true

Size: 1.57 KB

Versions: 6853

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

Version Path
cloudsmith-api-0.54.15 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.53.79 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.53.17 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.53.3 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.53.1 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.52.121 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.52.92 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.52.79 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.52.5 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.52.0 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.51.93 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.51.38 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.51.37 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.51.34 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.51.22 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
typhoeus-1.4.0 lib/rack/typhoeus/middleware/params_decoder.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/typhoeus-1.3.1/lib/rack/typhoeus/middleware/params_decoder.rb
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/typhoeus-1.3.1/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.49.118 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.3.1/lib/rack/typhoeus/middleware/params_decoder.rb
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/typhoeus-1.3.1/lib/rack/typhoeus/middleware/params_decoder.rb