uri: Add redirect tests for none, safe, urllib2 and all (#37068)

This is required if we want to ensure that #36809 doesn't cause any
important behavioral changes.

This PR changes the uri module to support follow_redirects=urllib2

It also adds a better error message when the connection closes before
any data was returned.
This commit is contained in:
Dag Wieers 2018-03-29 20:54:42 +02:00 committed by ansibot
commit 800dad5bdf
7 changed files with 1105 additions and 8 deletions

View file

@ -1050,6 +1050,8 @@ def fetch_url(module, url, data=None, headers=None, method=None,
info.update(dict(msg="Request failed: %s" % to_native(e), status=code))
except socket.error as e:
info.update(dict(msg="Connection failure: %s" % to_native(e), status=-1))
except httplib.BadStatusLine as e:
info.update(dict(msg="Connection failure: connection was closed before a valid response was received: %s" % to_native(e.line), status=-1))
except Exception as e:
info.update(dict(msg="An unknown error occurred: %s" % to_native(e), status=-1),
exception=traceback.format_exc())