diff options
author | Michel Ganguin <ganguin@romandie.com> | 2018-12-31 21:54:29 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2019-02-13 00:20:47 -0800 |
commit | 856abee86416d4b2159f81d34cf28ef3422b92ec (patch) | |
tree | a1fd501ed85612c611c1adab2f0a586d3ba99c2d | |
parent | selectors.py: handle ssl.CertificateError (bug 639156) (diff) | |
download | mirrorselect-856abee86416d4b2159f81d34cf28ef3422b92ec.tar.gz mirrorselect-856abee86416d4b2159f81d34cf28ef3422b92ec.tar.bz2 mirrorselect-856abee86416d4b2159f81d34cf28ef3422b92ec.zip |
selectors.py: Give urllib hostname info (bug 604968)
Give urllib hostname info such that:
* it will not fail when using HTTPS because of hostname mismatch (CertificateError)
* it will not fail when the server is a virtualhost
* it will not fail when the server validates ssl SNI
Bug: https://bugs.gentoo.org/566778
Bug: https://bugs.gentoo.org/604968
Bug: https://bugs.gentoo.org/639156
Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r-- | mirrorselect/selectors.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/mirrorselect/selectors.py b/mirrorselect/selectors.py index 33f7663..4b7e7a2 100644 --- a/mirrorselect/selectors.py +++ b/mirrorselect/selectors.py @@ -42,6 +42,7 @@ if sys.version_info[0] >= 3: url_parse = urllib.parse.urlparse url_unparse = urllib.parse.urlunparse url_open = urllib.request.urlopen + url_request = urllib.request.Request HTTPError = urllib.error.HTTPError import http.client IncompleteRead = http.client.IncompleteRead @@ -51,6 +52,7 @@ else: url_parse = urlparse.urlparse url_unparse = urlparse.urlunparse url_open = urllib2.urlopen + url_request = urllib2.Request HTTPError = urllib2.HTTPError import httplib IncompleteRead = httplib.IncompleteRead @@ -368,7 +370,9 @@ class Deep(object): try: signal.alarm(int(math.ceil(maxtime))) stime = time.time() - f = url_open(test_url) + r = url_request(test_url) + r.host = url_parts.netloc + f = url_open(r) md5 = hashlib.md5(f.read()).hexdigest() @@ -419,7 +423,9 @@ class Deep(object): try: try: signal.alarm(self._connect_timeout) - f = url_open(test_url) + r = url_request(test_url) + r.host = url_parts.netloc + f = url_open(r) early_out = True finally: signal.alarm(0) |