[get_url] Return status_code on HTTP 304 (#65739)

Return field status_code on HTTP status 304 (implemented by lkthomas)
Add an integration test for this case.
Fixes #65263
pull/65735/head
Baptiste Mille-Mathias 5 years ago committed by Sam Doran
parent 4351a756e1
commit 32a8b620f3

@ -0,0 +1,2 @@
bugfixes:
- "On HTTP status code 304, return status_code"

@ -365,7 +365,7 @@ def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, head
elapsed = (datetime.datetime.utcnow() - start).seconds
if info['status'] == 304:
module.exit_json(url=url, dest=dest, changed=False, msg=info.get('msg', ''), elapsed=elapsed)
module.exit_json(url=url, dest=dest, changed=False, msg=info.get('msg', ''), status_code=info['status'], elapsed=elapsed)
# Exceptions in fetch_url may result in a status -1, the ensures a proper error to the user in all cases
if info['status'] == -1:

@ -221,7 +221,7 @@
- result is changed
- "stat_result.stat.mode == '0707'"
- name: Test that setting file modes on an already downlaoded file work
- name: Test that setting file modes on an already downloaded file work
get_url:
url: 'https://{{ httpbin_host }}/'
dest: '{{ remote_tmp_dir }}/test'
@ -238,6 +238,19 @@
- result is changed
- "stat_result.stat.mode == '0070'"
# https://github.com/ansible/ansible/pull/65307/
- name: Test that on http status 304, we get a status_code field.
get_url:
url: 'https://{{ httpbin_host }}/status/304'
dest: '{{ remote_tmp_dir }}/test'
register: result
- name: Assert that we get the appropriate status_code
assert:
that:
- "'status_code' in result"
- "result.status_code == 304"
# https://github.com/ansible/ansible/issues/29614
- name: Change mode on an already downloaded file and specify checksum
get_url:

Loading…
Cancel
Save