summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2023-01-18 16:23:09 -0600
committerGitHub <noreply@github.com>2023-01-18 16:23:09 -0600
commita8642ef1b057b42220ca2689877ce871e835c5bf (patch)
treee4e231ddfe79234f0732b7822c05143c01441569
parentc83669a83e55ee500d9defe2f29affd64993f106 (diff)
downloadansible-a8642ef1b057b42220ca2689877ce871e835c5bf.tar.gz
[stable-2.14] Better json content type detection for uri (#79719) (#79726)
* Better json content type detection for uri * typo (cherry picked from commit 74cdffe) Co-authored-by: Matt Martz <matt@sivel.net>
-rw-r--r--changelogs/fragments/better-maybe-json-uri.yml2
-rw-r--r--lib/ansible/modules/uri.py6
2 files changed, 5 insertions, 3 deletions
diff --git a/changelogs/fragments/better-maybe-json-uri.yml b/changelogs/fragments/better-maybe-json-uri.yml
new file mode 100644
index 0000000000..c944032da3
--- /dev/null
+++ b/changelogs/fragments/better-maybe-json-uri.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- uri - improve JSON content type detection
diff --git a/lib/ansible/modules/uri.py b/lib/ansible/modules/uri.py
index 958aefc938..c00213644d 100644
--- a/lib/ansible/modules/uri.py
+++ b/lib/ansible/modules/uri.py
@@ -447,7 +447,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(
@@ -695,11 +695,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: