@ -65,6 +65,8 @@ options:
description :
description :
- The serialization format of the body . When set to json , encodes the
- The serialization format of the body . When set to json , encodes the
body argument , if needed , and automatically sets the Content - Type header accordingly .
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
required : false
choices : [ " raw " , " json " ]
choices : [ " raw " , " json " ]
default : raw
default : raw
@ -134,7 +136,9 @@ options:
default : null
default : null
headers :
headers :
description :
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
required : false
default : null
default : null
version_added : ' 2.1 '
version_added : ' 2.1 '
@ -399,7 +403,9 @@ def main():
# Encode the body unless its a string, then assume it is pre-formatted JSON
# Encode the body unless its a string, then assume it is pre-formatted JSON
if not isinstance ( body , basestring ) :
if not isinstance ( body , basestring ) :
body = json . dumps ( body )
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
# Grab all the http headers. Need this hack since passing multi-values is
# currently a bit ugly. (e.g. headers='{"Content-Type":"application/json"}')
# currently a bit ugly. (e.g. headers='{"Content-Type":"application/json"}')