lib/httpx/transcoder/form.rb in httpx-0.16.1 vs lib/httpx/transcoder/form.rb in httpx-0.17.0
- old
+ new
@@ -5,10 +5,12 @@
module HTTPX::Transcoder
module Form
module_function
+ PARAM_DEPTH_LIMIT = 32
+
class Encoder
extend Forwardable
def_delegator :@raw, :to_s
@@ -29,11 +31,29 @@
def content_type
"application/x-www-form-urlencoded"
end
end
+ module Decoder
+ module_function
+
+ def call(response, _)
+ URI.decode_www_form(response.to_s).each_with_object({}) do |(field, value), params|
+ HTTPX::Transcoder.normalize_query(params, field, value, PARAM_DEPTH_LIMIT)
+ end
+ end
+ end
+
def encode(form)
Encoder.new(form)
+ end
+
+ def decode(response)
+ content_type = response.content_type.mime_type
+
+ raise Error, "invalid form mime type (#{content_type})" unless content_type == "application/x-www-form-urlencoded"
+
+ Decoder
end
end
register "form", Form
end