Sha256: 8a4e69112c45203bd8c6bbf00bf3d183f2d2ad8660193a690c7499fd872c7920

Contents?: true

Size: 735 Bytes

Versions: 1

Compression:

Stored size: 735 Bytes

Contents

require 'rack/utils'

module Goliath
  module Rack
    # A middle ware to parse params. This will parse both the
    # query string parameters and the body and place them into
    # the _params_ hash of the Goliath::Env for the request.
    #
    # @example
    #  use Goliath::Rack::Params
    #
    class Params
      def initialize(app)
        @app = app
      end

      def call(env)
        env['params'] = retrieve_params(env)
        @app.call(env)
      end

      def retrieve_params(env)
        params = {}
        params.merge!(::Rack::Utils.parse_query(env['QUERY_STRING']))
        params.merge!(::Rack::Utils.parse_query(env['rack.input'].read)) unless env['rack.input'].nil?
        params
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
goliath-0.9.0 lib/goliath/rack/params.rb