lib/grape/http/request.rb in grape-0.12.0 vs lib/grape/http/request.rb in grape-0.13.0

- old
+ new

@@ -1,12 +1,17 @@ module Grape class Request < Rack::Request + ROUTING_ARGS = 'rack.routing_args' + HTTP_PREFIX = 'HTTP_' + UNDERSCORE = '_' + MINUS = '-' + def params @params ||= begin params = Hashie::Mash.new(super) - if env['rack.routing_args'] - args = env['rack.routing_args'].dup + if env[ROUTING_ARGS] + args = env[ROUTING_ARGS].dup # preserve version from query string parameters args.delete(:version) args.delete(:route_info) params.deep_merge!(args) end @@ -14,11 +19,14 @@ end end def headers @headers ||= env.dup.inject({}) do |h, (k, v)| - if k.to_s.start_with? 'HTTP_' - k = k[5..-1].tr('_', '-').downcase.gsub(/^.|[-_\s]./) { |x| x.upcase } + if k.to_s.start_with? HTTP_PREFIX + k = k[5..-1] + k.tr!(UNDERSCORE, MINUS) + k.downcase! + k.gsub!(/^.|[-_\s]./, &:upcase!) h[k] = v end h end end