From 109769435549355191f57d89ea1145e3c5c938a7 Mon Sep 17 00:00:00 2001 From: Zhanwei Wang Date: Sat, 11 Apr 2020 01:17:55 +0800 Subject: [PATCH] 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. --- .../fragments/67417-get_url-incorrect-if-modified-since.yaml | 2 ++ lib/ansible/module_utils/urls.py | 2 +- test/units/module_utils/urls/test_Request.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/67417-get_url-incorrect-if-modified-since.yaml 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 00000000000000..ee725ff26a19b7 --- /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 c896abdf74bca8..12ca9bc7a70ab9 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -1274,7 +1274,7 @@ def open(self, method, url, data=None, headers=None, use_proxy=None, 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 5c20f27ad1b65b..ebb6de56de67dc 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):