@ -61,9 +61,10 @@ options:
version_added : " 2.0 "
version_added : " 2.0 "
method :
method :
description :
description :
- The HTTP method of the request or response . It MUST be uppercase .
- The HTTP method of the request or response .
- In more recent versions we do not restrict the method at the module level anymore
but it still must be a valid method accepted by the service handling the request .
type : str
type : str
choices : [ CONNECT , DELETE , GET , HEAD , OPTIONS , PATCH , POST , PUT , REFRESH , TRACE ]
default : GET
default : GET
return_content :
return_content :
description :
description :
@ -303,6 +304,7 @@ import cgi
import datetime
import datetime
import json
import json
import os
import os
import re
import shutil
import shutil
import sys
import sys
import tempfile
import tempfile
@ -516,7 +518,7 @@ def main():
body = dict ( type = ' raw ' ) ,
body = dict ( type = ' raw ' ) ,
body_format = dict ( type = ' str ' , default = ' raw ' , choices = [ ' form-urlencoded ' , ' json ' , ' raw ' ] ) ,
body_format = dict ( type = ' str ' , default = ' raw ' , choices = [ ' form-urlencoded ' , ' json ' , ' raw ' ] ) ,
src = dict ( type = ' path ' ) ,
src = dict ( type = ' path ' ) ,
method = dict ( type = ' str ' , default = ' GET ' , choices = [ ' CONNECT ' , ' DELETE ' , ' GET ' , ' HEAD ' , ' OPTIONS ' , ' PATCH ' , ' POST ' , ' PUT ' , ' REFRESH ' , ' TRACE ' ] ),
method = dict ( type = ' str ' , default = ' GET ' ),
return_content = dict ( type = ' bool ' , default = False ) ,
return_content = dict ( type = ' bool ' , default = False ) ,
follow_redirects = dict ( type = ' str ' , default = ' safe ' , choices = [ ' all ' , ' no ' , ' none ' , ' safe ' , ' urllib2 ' , ' yes ' ] ) ,
follow_redirects = dict ( type = ' str ' , default = ' safe ' , choices = [ ' all ' , ' no ' , ' none ' , ' safe ' , ' urllib2 ' , ' yes ' ] ) ,
creates = dict ( type = ' path ' ) ,
creates = dict ( type = ' path ' ) ,
@ -538,7 +540,7 @@ def main():
url = module . params [ ' url ' ]
url = module . params [ ' url ' ]
body = module . params [ ' body ' ]
body = module . params [ ' body ' ]
body_format = module . params [ ' body_format ' ] . lower ( )
body_format = module . params [ ' body_format ' ] . lower ( )
method = module . params [ ' method ' ]
method = module . params [ ' method ' ] . upper ( )
dest = module . params [ ' dest ' ]
dest = module . params [ ' dest ' ]
return_content = module . params [ ' return_content ' ]
return_content = module . params [ ' return_content ' ]
creates = module . params [ ' creates ' ]
creates = module . params [ ' creates ' ]
@ -548,6 +550,9 @@ def main():
dict_headers = module . params [ ' headers ' ]
dict_headers = module . params [ ' headers ' ]
if not re . match ( ' ^[A-Z]+$ ' , method ) :
module . fail_json ( msg = " Parameter ' method ' needs to be a single word in uppercase, like GET or POST. " )
if body_format == ' json ' :
if body_format == ' json ' :
# 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 , string_types ) :
if not isinstance ( body , string_types ) :