Tighten use of form-encoding to only cases where a JSON body is not ever allowed

This commit is contained in:
Steve Bazyl committed 2016-09-08 13:40:30 -07:00
1 parent 6089c866ac
commit e13da8e05e
3 files changed
+20 -4

No files matched your search

+4
View File
@@ -105,6 +105,10 @@ module Google
end
end
def allow_form_encoding?
request_representation.nil? && super
end
private
# Attempt to parse a JSON error message, returning the first found error
+5 -1
View File
@@ -146,7 +146,7 @@ module Google
self.url = url.expand(params) if url.is_a?(Addressable::Template)
url.query_values = query.merge(url.query_values || {})
if [:post, :put].include?(method) && body.nil?
if allow_form_encoding?
@form_encoded = true
self.body = Addressable::URI.form_encode(url.query_values(Array))
self.header['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
@@ -306,6 +306,10 @@ module Google
req.options.open_timeout = options.open_timeout_sec
end
def allow_form_encoding?
[:post, :put].include?(method) && body.nil?
end
private
def form_encoded?