diff --git a/lib/httparty/request/body.rb b/lib/httparty/request/body.rb index 8fc2d225..ec7ae55b 100644 --- a/lib/httparty/request/body.rb +++ b/lib/httparty/request/body.rb @@ -22,7 +22,7 @@ def boundary end def multipart? - params.respond_to?(:to_hash) && (force_multipart || has_file?(params.to_hash)) + params.respond_to?(:to_hash) && (force_multipart || file?(params)) end private @@ -46,26 +46,16 @@ def generate_multipart multipart += "--#{boundary}--\r\n" end - def has_file?(hash) - hash.detect do |key, value| - if value.respond_to?(:to_hash) || includes_hash?(value) - has_file?(value) - elsif value.respond_to?(:to_ary) - value.any? { |e| file?(e) } - else - file?(value) - end + def file?(value) + if value.respond_to?(:to_hash) + value.to_hash.any? { |_, v| file?(v) } + elsif value.respond_to?(:to_ary) + value.to_ary.any? { |v| file?(v) } + else + value.respond_to?(:path) && value.respond_to?(:read) end end - def file?(object) - object.respond_to?(:path) && object.respond_to?(:read) # add memoization - end - - def includes_hash?(object) - object.respond_to?(:to_ary) && object.any? { |e| e.respond_to?(:hash) } - end - def normalize_query(query) if query_string_normalizer query_string_normalizer.call(query)