Sha256: 9de600c0a525014a5b1c3a68311f945fa3f893059e9146a0ba6e2e81f2234abb

Contents?: true

Size: 835 Bytes

Versions: 5

Compression:

Stored size: 835 Bytes

Contents

module Grape
  class Request < Rack::Request
    HTTP_PREFIX = 'HTTP_'.freeze

    alias rack_params params

    def params
      @params ||= build_params
    end

    def headers
      @headers ||= build_headers
    end

    private

    def build_params
      params = Hashie::Mash.new(rack_params)
      if env[Grape::Env::GRAPE_ROUTING_ARGS]
        args = env[Grape::Env::GRAPE_ROUTING_ARGS].dup
        # preserve version from query string parameters
        args.delete(:version)
        args.delete(:route_info)
        params.deep_merge!(args)
      end
      params
    end

    def build_headers
      headers = {}
      env.each_pair do |k, v|
        next unless k.to_s.start_with? HTTP_PREFIX

        k = k[5..-1].split('_').each(&:capitalize!).join('-')
        headers[k] = v
      end
      headers
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grape-0.19.2 lib/grape/request.rb
grape-0.19.1 lib/grape/request.rb
grape-0.19.0 lib/grape/request.rb
grape-0.18.0 lib/grape/request.rb
grape-0.17.0 lib/grape/request.rb