1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Don't pass follow_redirects to fetch_url, use module.params instead

This commit is contained in:
Matt Martz 2016-03-07 15:34:22 -06:00 committed by Matt Clay
parent b61d531dfc
commit fe22ee9423

View file

@ -297,12 +297,16 @@ def uri(module, url, dest, body, body_format, method, headers, socket_timeout):
redir_info = {}
r = {}
if dest is not None:
# Stash follow_redirects, in this block we don't want to follow
# we'll reset back to the supplied value soon
follow_redirects = module.params['follow_redirects']
module.params['follow_redirects'] = False
dest = os.path.expanduser(dest)
if os.path.isdir(dest):
# first check if we are redirected to a file download
_, redir_info = fetch_url(module, url, data=body,
headers=headers,
method=method, follow_redirects=None,
method=method,
timeout=socket_timeout)
# if we are redirected, update the url with the location header,
# and update dest with the new url filename
@ -316,6 +320,9 @@ def uri(module, url, dest, body, body_format, method, headers, socket_timeout):
tstamp = t.strftime('%a, %d %b %Y %H:%M:%S +0000')
headers['If-Modified-Since'] = tstamp
# Reset follow_redirects back to the stashed value
module.params['follow_redirects'] = follow_redirects
resp, info = fetch_url(module, url, data=body, headers=headers,
method=method, timeout=socket_timeout)
r['redirected'] = redirected or info['url'] != url