-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathrequest.rb
41 lines (33 loc) · 880 Bytes
/
request.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Grape
class Request < Rack::Request
HTTP_PREFIX = 'HTTP_'.freeze
alias rack_params params
def initialize(env, options = {})
extend options[:build_params_with] || Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder
super(env)
end
def params
@params ||= build_params
end
def headers
@headers ||= build_headers
end
private
def grape_routing_args
args = env[Grape::Env::GRAPE_ROUTING_ARGS].dup
# preserve version from query string parameters
args.delete(:version)
args.delete(:route_info)
args
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