lib/httpx/plugins/multipart.rb in httpx-0.16.1 vs lib/httpx/plugins/multipart.rb in httpx-0.17.0
- old
+ new
@@ -34,10 +34,11 @@
end
rescue LoadError
end
# :nocov:
require "httpx/plugins/multipart/encoder"
+ require "httpx/plugins/multipart/decoder"
require "httpx/plugins/multipart/part"
require "httpx/plugins/multipart/mime_type_detector"
end
def configure(*)
@@ -51,9 +52,22 @@
def encode(form)
if multipart?(form)
Encoder.new(form)
else
Transcoder::Form::Encoder.new(form)
+ end
+ end
+
+ def decode(response)
+ content_type = response.content_type.mime_type
+
+ case content_type
+ when "application/x-www-form-urlencoded"
+ Transcoder::Form.decode(response)
+ when "multipart/form-data"
+ Decoder.new(response)
+ else
+ raise Error, "invalid form mime type (#{content_type})"
end
end
def multipart?(data)
data.any? do |_, v|