Skip to content

Commit

Permalink
remove data encoding to json
Browse files Browse the repository at this point in the history
This commit removes the logic to encode the payload before sending the
request.  This library should not attempt to infer the data type and
simply add the data to the request exactly as it was passed to the
function.  It is the responsibility of the upstream function to call the
function with the appropriately encoded data.

This commit will now check if the value of data is type of bytes and
raise an exception if it is not
  • Loading branch information
privateip committed Dec 18, 2024
1 parent a552e15 commit 0e89cf3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions plugins/module_utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def send_request(method, url, headers=None, data=None, params=None, auth=None, t
if certificate_file is not None and private_key_file is not None:
kwargs["cert"] = (certificate_file, private_key_file)

if isinstance(kwargs.get("data"), (dict, list)) and kwargs.get("data"):
kwargs["data"] = json.dumps(data)
if data is not None:
if not isinstance(data, bytes):
raise AnsibleError(f"invalid type for data, expected bytes, got {type(data)}")
kwargs["data"] = data

display.vvvvv(f"Request object: {kwargs}")

Expand Down

0 comments on commit 0e89cf3

Please sign in to comment.