Merge pull request #2119 from jpmens/uri_json
uri: load JSON for content-type: application/json
This commit is contained in:
commit
7a7d02073a
1 changed files with 9 additions and 1 deletions
10
library/uri
10
library/uri
|
@ -71,7 +71,7 @@ options:
|
||||||
default: "GET"
|
default: "GET"
|
||||||
return_content:
|
return_content:
|
||||||
description:
|
description:
|
||||||
- Whether or not to return the body of the request as a "content" key in the dictionary result.
|
- Whether or not to return the body of the request as a "content" key in the dictionary result. If the reported Content-type is "application/json", then the JSON is additionally loaded into a key called C(json) in the dictionary results.
|
||||||
required: false
|
required: false
|
||||||
choices: [ "yes", "no" ]
|
choices: [ "yes", "no" ]
|
||||||
default: "no"
|
default: "no"
|
||||||
|
@ -360,6 +360,14 @@ def main():
|
||||||
ukey = key.replace("-", "_")
|
ukey = key.replace("-", "_")
|
||||||
uresp[ukey] = value
|
uresp[ukey] = value
|
||||||
|
|
||||||
|
if 'content_type' in uresp:
|
||||||
|
if uresp['content_type'].startswith('application/json'):
|
||||||
|
try:
|
||||||
|
js = json.loads(content)
|
||||||
|
uresp['json'] = js
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if resp['status'] != status_code:
|
if resp['status'] != status_code:
|
||||||
module.fail_json(msg="Status code was not " + status_code, content=content, **uresp)
|
module.fail_json(msg="Status code was not " + status_code, content=content, **uresp)
|
||||||
elif return_content:
|
elif return_content:
|
||||||
|
|
Loading…
Reference in a new issue