Better json content type detection for uri (#79719)

* Better json content type detection for uri

* typo
This commit is contained in:
Matt Martz
2023-01-12 13:11:31 -06:00
committed by GitHub
parent 2143bcd6b1
commit 74cdffe30d
2 changed files with 5 additions and 3 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- uri - improve JSON content type detection

View File

@ -448,7 +448,7 @@ from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.common._collections_compat import Mapping, Sequence
from ansible.module_utils.urls import fetch_url, get_response_filename, parse_content_type, prepare_multipart, url_argument_spec
JSON_CANDIDATES = ('text', 'json', 'javascript')
JSON_CANDIDATES = {'json', 'javascript'}
# List of response key names we do not want sanitize_keys() to change.
NO_MODIFY_KEYS = frozenset(
@ -696,11 +696,11 @@ def main():
content_type, main_type, sub_type, content_encoding = parse_content_type(r)
else:
content_type = 'application/octet-stream'
main_type = 'aplication'
main_type = 'application'
sub_type = 'octet-stream'
content_encoding = 'utf-8'
maybe_json = content_type and any(candidate in sub_type for candidate in JSON_CANDIDATES)
maybe_json = content_type and sub_type.lower() in JSON_CANDIDATES
maybe_output = maybe_json or return_content or info['status'] not in status_code
if maybe_output: