commit:     856abee86416d4b2159f81d34cf28ef3422b92ec
Author:     Michel Ganguin <ganguin <AT> romandie <DOT> com>
AuthorDate: Mon Dec 31 21:54:29 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Feb 13 08:20:47 2019 +0000
URL:        https://gitweb.gentoo.org/proj/mirrorselect.git/commit/?id=856abee8

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 <AT> gentoo.org>

 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)

Reply via email to