mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
* Only add Content-Type if not specified in headers. Fixes #20046 * Update documentation to indicate body_format will not override Content-Type if specified in headers
This commit is contained in:
parent
0988de8c4c
commit
d25a70846f
2 changed files with 21 additions and 2 deletions
|
@ -65,6 +65,8 @@ options:
|
|||
description:
|
||||
- The serialization format of the body. When set to json, encodes the
|
||||
body argument, if needed, and automatically sets the Content-Type header accordingly.
|
||||
As of C(2.3) it is possible to override the `Content-Type` header, when
|
||||
set to json via the I(headers) option.
|
||||
required: false
|
||||
choices: [ "raw", "json" ]
|
||||
default: raw
|
||||
|
@ -134,7 +136,9 @@ options:
|
|||
default: null
|
||||
headers:
|
||||
description:
|
||||
- Add custom HTTP headers to a request in the format of a YAML hash
|
||||
- Add custom HTTP headers to a request in the format of a YAML hash. As
|
||||
of C(2.3) supplying C(Content-Type) here will override the header
|
||||
generated by supplying C(json) for I(body_format).
|
||||
required: false
|
||||
default: null
|
||||
version_added: '2.1'
|
||||
|
@ -399,7 +403,9 @@ def main():
|
|||
# Encode the body unless its a string, then assume it is pre-formatted JSON
|
||||
if not isinstance(body, basestring):
|
||||
body = json.dumps(body)
|
||||
dict_headers['Content-Type'] = 'application/json'
|
||||
lower_header_keys = [key.lower() for key in dict_headers]
|
||||
if 'content-type' not in lower_header_keys:
|
||||
dict_headers['Content-Type'] = 'application/json'
|
||||
|
||||
# Grab all the http headers. Need this hack since passing multi-values is
|
||||
# currently a bit ugly. (e.g. headers='{"Content-Type":"application/json"}')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue