mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
Merge pull request #98 from PRX/master
like pull request 97 for multipart check failing when there is an array in the request, but recursive
This commit is contained in:
commit
790d8d3b18
@ -21,12 +21,11 @@ module Faraday
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_multipart?(body)
|
def has_multipart?(obj)
|
||||||
body.values.each do |val|
|
# string is an enum in 1.8, returning list of itself
|
||||||
if val.respond_to?(:content_type)
|
if obj.respond_to?(:each) && !obj.is_a?(String)
|
||||||
return true
|
(obj.respond_to?(:values) ? obj.values : obj).each do |val|
|
||||||
elsif val.respond_to?(:values)
|
return true if (val.respond_to?(:content_type) || has_multipart?(val))
|
||||||
return true if has_multipart?(val)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
|
@ -113,4 +113,27 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|||||||
end
|
end
|
||||||
assert_equal [], regexes
|
assert_equal [], regexes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_multipart_with_arrays
|
||||||
|
# assume params are out of order
|
||||||
|
regexes = [
|
||||||
|
/name\=\"a\"/,
|
||||||
|
/name=\"b\[\]\[c\]\"\; filename\=\"request_middleware_test\.rb\"/,
|
||||||
|
/name=\"b\[\]\[d\]\"/]
|
||||||
|
|
||||||
|
payload = {:a => 1, :b =>[{:c => Faraday::UploadIO.new(__FILE__, 'text/x-ruby'), :d => 2}]}
|
||||||
|
response = @conn.post('/echo', payload)
|
||||||
|
|
||||||
|
assert_kind_of Faraday::CompositeReadIO, response.body
|
||||||
|
assert_equal "multipart/form-data;boundary=%s" % Faraday::Request::Multipart::DEFAULT_BOUNDARY,
|
||||||
|
response.headers['Content-Type']
|
||||||
|
|
||||||
|
response.body.send(:ios).map{|io| io.read}.each do |io|
|
||||||
|
if re = regexes.detect { |r| io =~ r }
|
||||||
|
regexes.delete re
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_equal [], regexes
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user