Skip to content

Commit

Permalink
Handle a missing rack.input in the env
Browse files Browse the repository at this point in the history
Ever since rack/rack#2018 `rack.input` has been
optional so we can't assume it's there and call `read` or `rewind` on it in
`Apipie::Extractor::Recorder`. Using safe navigation to call these methods
seems like the simplest approach because we want to look for
`rack.request.form_hash` instead in both the situation where `rack.input` is
missing, or it's empty.
  • Loading branch information
h-lame committed Jul 5, 2024
1 parent a697e7a commit a178e6d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/apipie/extractor/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def analyse_env(env)
@params = Rack::Utils.parse_nested_query(@query)
@params.merge!(env["action_dispatch.request.request_parameters"] || {})
rack_input = env["rack.input"]
if data = parse_data(rack_input.read)
if data = parse_data(rack_input&.read)
@request_data = data
elsif form_hash = env["rack.request.form_hash"]
@request_data = reformat_multipart_data(form_hash)
end
rack_input.rewind
rack_input&.rewind
end

def analyse_controller(controller)
Expand Down

0 comments on commit a178e6d

Please sign in to comment.