Sha256: 41ca1d952f0f19d26c7497fb37c93ba86a476820550e93e03cd8575896fbe6ef

Contents?: true

Size: 1.57 KB

Versions: 6915

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

Version Path
ory-client-0.0.1.alpha36 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.8.2.alpha1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.7.6.alpha3 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.7.6.alpha1 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb
ory-kratos-client-0.7.5.alpha2 vendor/bundle/ruby/2.5.0/gems/typhoeus-1.4.0/lib/rack/typhoeus/middleware/params_decoder.rb