Sha256: 00d86a74840a03c0d3f6d51332116616511db5f2c7f7bb49557459e2d97fa043

Contents?: true

Size: 843 Bytes

Versions: 2

Compression:

Stored size: 843 Bytes

Contents

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

    alias_method :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::RACK_ROUTING_ARGS]
        args = env[Grape::Env::RACK_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

2 entries across 2 versions & 1 rubygems

Version Path
grape-0.15.0 lib/grape/request.rb
grape-0.14.0 lib/grape/request.rb