Class: Grape::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/grape/http/request.rb

Instance Method Summary collapse

Instance Method Details

#headersObject


17
18
19
20
21
22
23
24
25
# File 'lib/grape/http/request.rb', line 17

def headers
  @env['grape.request.headers'] ||= @env.dup.inject({}) do |h, (k, v)|
    if k.to_s.start_with? 'HTTP_'
      k = k[5..-1].gsub('_', '-').downcase.gsub(/^.|[-_\s]./) { |x| x.upcase }
      h[k] = v
    end
    h
  end
end

#paramsObject


4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/grape/http/request.rb', line 4

def params
  @env['grape.request.params'] = begin
    params = Hashie::Mash.new(super)
    if env['rack.routing_args']
      args = env['rack.routing_args'].dup
      # preserve version from query string parameters
      args.delete(:version)
      params.deep_merge!(args)
    end
    params
  end
end