mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +01:00
Use proxy for HTTPS requests as well
Use proxy handler/opener classes, instead of request.set_proxy, to avoid any potential bugs in older Python versions. Use the HTTP proxy (if configured) for HTTPS requests as well.
This commit is contained in:
parent
3879f30d47
commit
654d98c125
@ -57,6 +57,7 @@ if minisix.PY2:
|
|||||||
return urllib.urlencode(*args, **kwargs).encode()
|
return urllib.urlencode(*args, **kwargs).encode()
|
||||||
from urllib2 import HTTPError, URLError
|
from urllib2 import HTTPError, URLError
|
||||||
from urllib import splithost, splituser
|
from urllib import splithost, splituser
|
||||||
|
from urllib2 import build_opener, install_opener, ProxyHandler
|
||||||
else:
|
else:
|
||||||
from http.client import InvalidURL
|
from http.client import InvalidURL
|
||||||
from urllib.parse import urlsplit, urlunsplit, urlparse
|
from urllib.parse import urlsplit, urlunsplit, urlparse
|
||||||
@ -72,6 +73,7 @@ else:
|
|||||||
return urllib.parse.urlencode(*args, **kwargs)
|
return urllib.parse.urlencode(*args, **kwargs)
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
from urllib.parse import splithost, splituser
|
from urllib.parse import splithost, splituser
|
||||||
|
from urllib.request import build_opener, install_opener, ProxyHandler
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
@ -145,7 +147,12 @@ def getUrlFd(url, headers=None, data=None, timeout=None):
|
|||||||
request.add_data(data)
|
request.add_data(data)
|
||||||
httpProxy = force(proxy)
|
httpProxy = force(proxy)
|
||||||
if httpProxy:
|
if httpProxy:
|
||||||
request.set_proxy(httpProxy, 'http')
|
proxyHandler = ProxyHandler({
|
||||||
|
'http': httpProxy,
|
||||||
|
'https': httpProxy
|
||||||
|
})
|
||||||
|
proxyOpener = build_opener(proxyHandler)
|
||||||
|
install_opener(proxyOpener)
|
||||||
fd = urlopen(request, timeout=timeout)
|
fd = urlopen(request, timeout=timeout)
|
||||||
return fd
|
return fd
|
||||||
except socket.timeout as e:
|
except socket.timeout as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user