#475, #488 -- allow raw JSON if explicitly requested, fix empty body handling & test cleanup

This commit is contained in:
Steve Bazyl committed 2017-03-31 15:26:51 -07:00
1 parent 489378db58
commit 97ff7f4d9a
5 files changed
+49 -6

No files matched your search

+6 -1
View File
@@ -55,7 +55,11 @@ module Google
query[FIELDS_PARAM] = normalize_fields_param(query[FIELDS_PARAM]) if query.key?(FIELDS_PARAM)
if request_representation && request_object
header['Content-Type'] ||= JSON_CONTENT_TYPE
self.body = request_representation.new(request_object).to_json(user_options: { skip_undefined: true })
if options && options.skip_serialization
self.body = request_object
else
self.body = request_representation.new(request_object).to_json(user_options: { skip_undefined: true })
end
end
super
end
@@ -71,6 +75,7 @@ module Google
# noinspection RubyUnusedLocalVariable
def decode_response_body(content_type, body)
return super unless response_representation
return super if options && options.skip_deserialization
return super if content_type.nil?
return nil unless content_type.start_with?(JSON_CONTENT_TYPE)
instance = response_class.new
+1 -4
View File
@@ -156,10 +156,7 @@ module Google
@form_encoded = false
end
unless body
self.header['Content-Type'] = 'application/json'
self.header['Content-Length'] = 0
end
self.body = '' unless self.body
end
+9 -1
View File
@@ -27,7 +27,9 @@ module Google
:header,
:timeout_sec,
:open_timeout_sec,
:normalize_unicode)
:normalize_unicode,
:skip_serialization,
:skip_deserialization)
# General client options
class ClientOptions
@@ -59,6 +61,10 @@ module Google
# @return [Hash<String,String] Additional HTTP headers to include in requests
# @!attribute [rw] normalize_unicode
# @return [Boolean] True if unicode strings should be normalized in path parameters
# @!attribute [rw] skip_serialization
# @return [Boolean] True if body object should be treated as raw text instead of an object.
# @!attribute [rw] skip_deserialization
# @return [Boolean] True if response should be returned in raw form instead of deserialized.
# Get the default options
# @return [Google::Apis::RequestOptions]
@@ -84,5 +90,7 @@ module Google
RequestOptions.default.retries = 0
RequestOptions.default.open_timeout_sec = 20
RequestOptions.default.normalize_unicode = false
RequestOptions.default.skip_serialization = false
RequestOptions.default.skip_deserialization = false
end
end