• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-grape / grape / 13552872935

26 Feb 2025 08:34PM UTC coverage: 98.108% (-0.3%) from 98.389%
13552872935

Pull #2540

github

web-flow
Merge 625d752a2 into 0f57e01dc
Pull Request #2540: Deprecates Grape's Extensions for ParamsBuilder in favor of build_with

58 of 63 new or added lines in 13 files covered. (92.06%)

9 existing lines in 3 files now uncovered.

3578 of 3647 relevant lines covered (98.11%)

75684.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/lib/grape/request.rb
1
# frozen_string_literal: true
2

3
module Grape
60✔
4
  class Request < Rack::Request
60✔
5
    DEFAULT_PARAMS_BUILDER = :hash_with_indifferent_access
60✔
6
    HTTP_PREFIX = 'HTTP_'
60✔
7

8
    alias rack_params params
60✔
9

10
    def initialize(env, build_params_with: nil)
60✔
11
      super(env)
81,405✔
12
      @params_builder = Grape::ParamsBuilder.params_builder_for(build_params_with || Grape.config.param_builder)
81,405✔
13
    end
14

15
    def params
60✔
16
      @params ||= make_params
345,506✔
17
    end
18

19
    def headers
60✔
20
      @headers ||= build_headers
637✔
21
    end
22

23
    # needs to be public until extensions param_builder are removed
24
    def grape_routing_args
60✔
25
      # preserve version from query string parameters
26
      env[Grape::Env::GRAPE_ROUTING_ARGS]&.except(:version, :route_info) || {}
51,336✔
27
    end
28

29
    private
60✔
30

31
    def make_params
60✔
32
      @params_builder.call(rack_params).deep_merge!(grape_routing_args)
51,385✔
33
    rescue EOFError
NEW
34
      raise Grape::Exceptions::EmptyMessageBody.new(content_type)
×
35
    rescue Rack::Multipart::MultipartPartLimitError
36
      raise Grape::Exceptions::TooManyMultipartFiles.new(Rack::Utils.multipart_part_limit)
49✔
37
    end
38

39
    def build_headers
60✔
40
      each_header.with_object(Grape::Util::Header.new) do |(k, v), headers|
637✔
41
        next unless k.start_with? HTTP_PREFIX
9,406✔
42

43
        transformed_header = Grape::Http::Headers::HTTP_HEADERS[k] || transform_header(k)
941✔
44
        headers[transformed_header] = v
941✔
45
      end
46
    end
47

48
    def transform_header(header)
60✔
49
      -header[5..].tr('_', '-').downcase
245✔
50
    end
51
  end
52
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc