@@ -34,8 +34,10 @@ def field_encryption_call_api(self, func):
3434
3535 @wraps (func )
3636 def call_api_function (* args , ** kwargs ):
37- check_type = inspect .signature (func .__self__ .call_api ).parameters .get ("_check_type" ) is None
38- if check_type :
37+ original_parameters = inspect .signature (func .__self__ .call_api ).parameters
38+ check_type_is_none = original_parameters .get ("_check_type" ) is None
39+ preload_content_is_not_none = original_parameters .get ("_preload_content" ) is not None
40+ if check_type_is_none and preload_content_is_not_none :
3941 kwargs ["_preload_content" ] = False # version 4.3.1
4042 return func (* args , ** kwargs )
4143
@@ -75,10 +77,17 @@ def _encrypt_payload(self, headers, body):
7577
7678 conf = self ._encryption_conf
7779
78- if type (conf ) is FieldLevelEncryptionConfig :
79- return self .encrypt_field_level_payload (headers , conf , body )
80- else :
81- return self .encrypt_jwe_payload (conf , body )
80+ encrypted_payload = self .encrypt_field_level_payload (headers , conf , body ) if type (
81+ conf ) is FieldLevelEncryptionConfig else self .encrypt_jwe_payload (conf , body )
82+
83+ # convert the encrypted_payload to the same data type as the input body
84+ if isinstance (body , str ):
85+ return json .dumps (encrypted_payload )
86+
87+ if isinstance (body , bytes ):
88+ return json .dumps (encrypted_payload ).encode ("utf-8" )
89+
90+ return encrypted_payload
8291
8392 def _decrypt_payload (self , headers , body ):
8493 """Encryption enforcement based on configuration - decrypt using session key params from header or body"""
0 commit comments