diff options
author | Zhanwei Wang <wang@hashdata.cn> | 2020-04-11 01:17:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-10 12:17:55 -0500 |
commit | 109769435549355191f57d89ea1145e3c5c938a7 (patch) | |
tree | 46b52312c0dcac9e5a0dae4fa0d35da02a53c995 | |
parent | 25650cb592240f1efd57832dbc808f997c3bf381 (diff) | |
download | ansible-109769435549355191f57d89ea1145e3c5c938a7.tar.gz |
get_url pass incorrect If-Modified-Since header(#67417) (#67419)
Fix #67417. HTTP header value of `If-Modified-Since` set by `get_url` does not follow HTTP protocol.
-rw-r--r-- | changelogs/fragments/67417-get_url-incorrect-if-modified-since.yaml | 2 | ||||
-rw-r--r-- | lib/ansible/module_utils/urls.py | 2 | ||||
-rw-r--r-- | test/units/module_utils/urls/test_Request.py | 2 |
3 files changed, 4 insertions, 2 deletions
diff --git a/changelogs/fragments/67417-get_url-incorrect-if-modified-since.yaml b/changelogs/fragments/67417-get_url-incorrect-if-modified-since.yaml new file mode 100644 index 0000000000..ee725ff26a --- /dev/null +++ b/changelogs/fragments/67417-get_url-incorrect-if-modified-since.yaml @@ -0,0 +1,2 @@ +bugfixes: + - get_url pass incorrect If-Modified-Since header (https://github.com/ansible/ansible/issues/67417) diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index c896abdf74..12ca9bc7a7 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -1274,7 +1274,7 @@ class Request: request.add_header('cache-control', 'no-cache') # or we do it if the original is more recent than our copy elif last_mod_time: - tstamp = rfc2822_date_string(last_mod_time.timetuple()) + tstamp = rfc2822_date_string(last_mod_time.timetuple(), 'GMT') request.add_header('If-Modified-Since', tstamp) # user defined headers now, which may override things we've set above diff --git a/test/units/module_utils/urls/test_Request.py b/test/units/module_utils/urls/test_Request.py index 5c20f27ad1..ebb6de56de 100644 --- a/test/units/module_utils/urls/test_Request.py +++ b/test/units/module_utils/urls/test_Request.py @@ -415,7 +415,7 @@ def test_Request_open_last_mod(urlopen_mock, install_opener_mock): args = urlopen_mock.call_args[0] req = args[0] - assert req.headers.get('If-modified-since') == now.strftime('%a, %d %b %Y %H:%M:%S -0000') + assert req.headers.get('If-modified-since') == now.strftime('%a, %d %b %Y %H:%M:%S GMT') def test_Request_open_headers_not_dict(urlopen_mock, install_opener_mock): |