Sha256: 7f99c43b3a7984b00432bed2d4092c8420785d578679c3549398b04e0e40634c

Contents?: true

Size: 1.26 KB

Versions: 14

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

class Rage::ParamsParser
  def self.prepare(env, url_params)
    has_body, query_string, content_type = env["IODINE_HAS_BODY"], env["QUERY_STRING"], env["CONTENT_TYPE"]

    query_params = Iodine::Rack::Utils.parse_nested_query(query_string) if query_string != ""
    unless has_body
      if query_params
        return query_params.merge!(url_params)
      else
        return url_params
      end
    end

    request_params = if content_type.start_with?("application/json")
      json_parse(env["rack.input"].read)
    elsif content_type.start_with?("application/x-www-form-urlencoded")
      Iodine::Rack::Utils.parse_urlencoded_nested_query(env["rack.input"].read)
    else
      Iodine::Rack::Utils.parse_multipart(env["rack.input"], content_type)
    end

    if request_params && !query_params
      request_params.merge!(url_params)
    elsif request_params && query_params
      request_params.merge!(query_params, url_params)
    else
      url_params
    end

  rescue => e
    raise Rage::Errors::BadRequest
  end

  if defined?(::FastJsonparser)
    def self.json_parse(json)
      FastJsonparser.parse(json, symbolize_keys: true)
    end
  else
    def self.json_parse(json)
      JSON.parse(json, symbolize_names: true)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rage-rb-1.6.0 lib/rage/params_parser.rb
rage-rb-1.4.0 lib/rage/params_parser.rb
rage-rb-1.3.0 lib/rage/params_parser.rb
rage-rb-1.2.2 lib/rage/params_parser.rb
rage-rb-1.2.1 lib/rage/params_parser.rb
rage-rb-1.2.0 lib/rage/params_parser.rb
rage-rb-1.1.0 lib/rage/params_parser.rb
rage-rb-1.0.0 lib/rage/params_parser.rb
rage-rb-0.7.0 lib/rage/params_parser.rb
rage-rb-0.6.0 lib/rage/params_parser.rb
rage-rb-0.5.2 lib/rage/params_parser.rb
rage-rb-0.5.1 lib/rage/params_parser.rb
rage-rb-0.5.0 lib/rage/params_parser.rb
rage-rb-0.4.0 lib/rage/params_parser.rb