use new proxy configuration and hardened it's usage
This commit is contained in:
parent
6238a4b98a
commit
38fe92e05e
|
@ -590,7 +590,7 @@ class ValidUrlWidget(UrlWidget):
|
|||
response, status, page, auth_header = misc.http_get_page(self.value)
|
||||
except Exception, msg:
|
||||
# If the proxy is configured and the connection failed, try without the proxy
|
||||
if not get_cfg('use_proxy'):
|
||||
if not get_cfg('proxy', {}).get('enabled'):
|
||||
self.error = msg
|
||||
else:
|
||||
try:
|
||||
|
|
|
@ -331,24 +331,30 @@ def _http_request(url, method='GET', body=None, headers={}, use_proxy=True):
|
|||
else:
|
||||
hostname, query = urllib.splithost(url[6:])
|
||||
|
||||
if use_proxy is False or not get_cfg('use_proxy'):
|
||||
proxy = False
|
||||
proxy_cfg = get_cfg('proxy', {})
|
||||
if use_proxy is True and proxy_cfg.get('enabled'):
|
||||
proxy_ip = proxy_cfg.get('ip')
|
||||
proxy_port = proxy_cfg.get('port')
|
||||
proxy_user = proxy_cfg.get('user')
|
||||
proxy_password = proxy_cfg.get('password')
|
||||
if proxy_ip and proxy_port:
|
||||
proxy = True
|
||||
conn = httplib.HTTPConnection('%s:%s' % (proxy_ip, proxy_port))
|
||||
query = url
|
||||
if proxy_user and proxy_password:
|
||||
credentials = base64.encodestring('%s:%s' % (proxy_user, proxy_password))[:-1]
|
||||
auth = 'Basic %s' % credentials
|
||||
headers['Proxy-Authorization'] = auth
|
||||
headers['Proxy-Connection'] = 'keep-alive'
|
||||
headers['Keep-Alive'] = '300'
|
||||
|
||||
if not proxy:
|
||||
if url.startswith('http://'):
|
||||
conn = httplib.HTTPConnection(hostname)
|
||||
else:
|
||||
conn = httplib.HTTPSConnection(hostname)
|
||||
query = query.replace('&', '&')
|
||||
else:
|
||||
proxy_hostname = '%s:%s' % (get_cfg('proxy_ip'), get_cfg('proxy_port'))
|
||||
conn = httplib.HTTPConnection(proxy_hostname)
|
||||
query = url
|
||||
user = get_cfg('proxy_user')
|
||||
if user is not None and user != '':
|
||||
proxy_password = get_cfg('proxy_password')
|
||||
credentials = base64.encodestring('%s:%s' % (user, proxy_password))[:-1]
|
||||
auth = 'Basic %s' % credentials
|
||||
headers['Proxy-Authorization'] = auth
|
||||
headers['Proxy-Connection'] = 'keep-alive'
|
||||
headers['Keep-Alive'] = '300'
|
||||
|
||||
try:
|
||||
conn.request(method, query, body, headers)
|
||||
|
|
Loading…
Reference in New Issue