Skip to content

Commit

Permalink
get_url pass incorrect If-Modified-Since header(#67417) (#67419)
Browse files Browse the repository at this point in the history
Fix #67417. HTTP header value of `If-Modified-Since` set by `get_url` does not follow HTTP protocol.

(cherry picked from commit 1097694)
  • Loading branch information
wangzw authored and mattclay committed Apr 14, 2020
1 parent bf3cd04 commit f7c63c1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
@@ -0,0 +1,2 @@
bugfixes:
- get_url pass incorrect If-Modified-Since header (https://github.com/ansible/ansible/issues/67417)
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/urls.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/units/module_utils/urls/test_Request.py
Expand Up @@ -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):
Expand Down

0 comments on commit f7c63c1

Please sign in to comment.