diff --git a/library/network/get_url b/library/network/get_url index 740eb631b12..28ee72a51f3 100644 --- a/library/network/get_url +++ b/library/network/get_url @@ -130,7 +130,7 @@ def url_filename(url): return 'index.html' return fn -def url_do_get(module, url, dest, use_proxy, last_mod_time): +def url_do_get(module, url, dest, use_proxy, last_mod_time, force): """ Get url and return request and info Credits: http://stackoverflow.com/questions/7006574/how-to-download-file-from-ftp @@ -176,9 +176,11 @@ def url_do_get(module, url, dest, use_proxy, last_mod_time): request = urllib2.Request(url) request.add_header('User-agent', USERAGENT) - if last_mod_time: + if last_mod_time and not force: tstamp = last_mod_time.strftime('%a, %d %b %Y %H:%M:%S +0000') request.add_header('If-Modified-Since', tstamp) + else: + request.add_header('cache-control', 'no-cache') try: r = urllib2.urlopen(request) @@ -194,16 +196,15 @@ def url_do_get(module, url, dest, use_proxy, last_mod_time): return r, info -def url_get(module, url, dest, use_proxy, last_mod_time): +def url_get(module, url, dest, use_proxy, last_mod_time, force): """ Download data from the url and store in a temporary file. Return (tempfile, info about the request) """ - req, info = url_do_get(module, url, dest, use_proxy, last_mod_time) + req, info = url_do_get(module, url, dest, use_proxy, last_mod_time, force) - # TODO: should really handle 304, but how? src file could exist (and be newer) but empty if info['status'] == 304: module.exit_json(url=url, dest=dest, changed=False, msg=info.get('msg', '')) @@ -283,7 +284,7 @@ def main(): last_mod_time = datetime.datetime.utcfromtimestamp(mtime) # download to tmpsrc - tmpsrc, info = url_get(module, url, dest, use_proxy, last_mod_time) + tmpsrc, info = url_get(module, url, dest, use_proxy, last_mod_time, force) # Now the request has completed, we can finally generate the final # destination file name from the info dict.