Skip to content

Commit

Permalink
Fix issues with multipart?
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilioCristalli committed Nov 30, 2018
1 parent ea6a085 commit 891ca8d
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions lib/httparty/request/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 891ca8d

Please sign in to comment.