lib/grape/request.rb in grape-1.3.0 vs lib/grape/request.rb in grape-1.3.1

- old
+ new

@@ -1,7 +1,9 @@ # frozen_string_literal: true +require 'grape/util/lazy_object' + module Grape class Request < Rack::Request HTTP_PREFIX = 'HTTP_' alias rack_params params @@ -28,16 +30,19 @@ 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 + Grape::Util::LazyObject.new do + env.each_pair.with_object({}) do |(k, v), headers| + next unless k.to_s.start_with? HTTP_PREFIX + transformed_header = Grape::Http::Headers::HTTP_HEADERS[k] || transform_header(k) + headers[transformed_header] = v + end end - headers + end + + def transform_header(header) + -header[5..-1].split('_').each(&:capitalize!).join('-') end end end