From 856abee86416d4b2159f81d34cf28ef3422b92ec Mon Sep 17 00:00:00 2001 From: Michel Ganguin Date: Mon, 31 Dec 2018 21:54:29 +0000 Subject: 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 --- mirrorselect/selectors.py | 10 ++++++++-- 1 file 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) -- cgit v1.2.3-65-gdbad