mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix get_https_resource_securely not handling redirects
This commit is contained in:
parent
f9873ab3ca
commit
f4ecd086bd
@ -23,6 +23,7 @@ class HTTPError(ValueError):
|
|||||||
self.code = code
|
self.code = code
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
|
|
||||||
if ispy3:
|
if ispy3:
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
@ -171,8 +172,9 @@ def get_https_resource_securely(
|
|||||||
ssl_version = ssl.PROTOCOL_TLSv1_2
|
ssl_version = ssl.PROTOCOL_TLSv1_2
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
ssl_version = ssl.PROTOCOL_TLSv1 # old python
|
ssl_version = ssl.PROTOCOL_TLSv1 # old python
|
||||||
|
cert_file = None
|
||||||
if cacerts is not None:
|
if cacerts is not None:
|
||||||
cacerts = P(cacerts, allow_user_override=False)
|
cert_file = P(cacerts, allow_user_override=False)
|
||||||
p = urlparse(url)
|
p = urlparse(url)
|
||||||
if p.scheme != 'https':
|
if p.scheme != 'https':
|
||||||
raise ValueError('URL %s scheme must be https, not %r' % (url, p.scheme))
|
raise ValueError('URL %s scheme must be https, not %r' % (url, p.scheme))
|
||||||
@ -192,7 +194,7 @@ def get_https_resource_securely(
|
|||||||
# Invalid proxy, ignore
|
# Invalid proxy, ignore
|
||||||
pass
|
pass
|
||||||
|
|
||||||
c = HTTPSConnection(ssl_version, hostname, port, cert_file=cacerts, timeout=timeout)
|
c = HTTPSConnection(ssl_version, hostname, port, cert_file=cert_file, timeout=timeout)
|
||||||
if has_proxy:
|
if has_proxy:
|
||||||
c.set_tunnel(p.hostname, p.port)
|
c.set_tunnel(p.hostname, p.port)
|
||||||
|
|
||||||
@ -217,6 +219,6 @@ def get_https_resource_securely(
|
|||||||
return response
|
return response
|
||||||
return response.read()
|
return response.read()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print (get_https_resource_securely('https://code.calibre-ebook.com/latest'))
|
print (get_https_resource_securely('https://code.calibre-ebook.com/latest'))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user